From 1ebb5b1fa0387aefe3acc8eabed92f7ee207e591 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Fri, 17 Dec 2021 01:46:40 +0300
Subject: [PATCH 09/15] EXPERIMENT: update bdwrite for lpcm/hevc

---
 cinelerra-5.1/cinelerra/bdwrite.C | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/bdwrite.C b/cinelerra-5.1/cinelerra/bdwrite.C
index 6a2b4ca3..b184e0c6 100644
--- a/cinelerra-5.1/cinelerra/bdwrite.C
+++ b/cinelerra-5.1/cinelerra/bdwrite.C
@@ -102,6 +102,7 @@ enum {
   BLURAY_STREAM_TYPE_VIDEO_VC1 = 0xea,
   BLURAY_STREAM_TYPE_VIDEO_H264 = 0x1b,
   BLURAY_STREAM_TYPE_VIDEO_H264_MVC = 0x20,
+  BLURAY_STREAM_TYPE_VIDEO_HEVC = 0x24,
   BLURAY_STREAM_TYPE_SUB_PG = 0x90,
   BLURAY_STREAM_TYPE_SUB_IG = 0x91,
   BLURAY_STREAM_TYPE_SUB_TEXT = 0x92,
@@ -122,6 +123,7 @@ enum {
   BLURAY_VIDEO_FORMAT_720P = 5,  // SMPTE 296M
   BLURAY_VIDEO_FORMAT_1080P = 6, // SMPTE 274M
   BLURAY_VIDEO_FORMAT_576P = 7,  // ITU-R BT.1358
+  BLURAY_VIDEO_FORMAT_2160P = 8,
 
   BLURAY_VIDEO_RATE_24000_1001 = 1, // 23.976
   BLURAY_VIDEO_RATE_24 = 2,
@@ -1505,6 +1507,7 @@ clpi_prog_stream::write()
   case BLURAY_STREAM_TYPE_VIDEO_MPEG2:
   case BLURAY_STREAM_TYPE_VIDEO_VC1:
   case BLURAY_STREAM_TYPE_VIDEO_H264:
+  case BLURAY_STREAM_TYPE_VIDEO_HEVC:
   case 0x20:
     bs.write(format, 4);
     bs.write(rate, 4);
@@ -1905,18 +1908,18 @@ write()
 
   bs.write(stream_type, 8);
   switch (stream_type) {
-  case 0x01:
+  case BLURAY_STREAM_TYPE_VIDEO_MPEG1:
     bs.write(pid, 16);
     break;
 
-  case 0x02:
-  case 0x04:
+  case BLURAY_STREAM_TYPE_VIDEO_MPEG2:
+  case BLURAY_STREAM_TYPE_AUDIO_MPEG2:
     bs.write(subpath_id, 8);
     bs.write(subclip_id, 8);
     bs.write(pid, 16);
     break;
 
-  case 0x03:
+  case BLURAY_STREAM_TYPE_AUDIO_MPEG1:
     bs.write(subpath_id, 8);
     bs.write(pid, 16);
     break;
@@ -1935,6 +1938,7 @@ write()
   case BLURAY_STREAM_TYPE_VIDEO_MPEG2:
   case BLURAY_STREAM_TYPE_VIDEO_VC1:
   case BLURAY_STREAM_TYPE_VIDEO_H264:
+  case BLURAY_STREAM_TYPE_VIDEO_HEVC:
     bs.write(format, 4);
     bs.write(rate, 4);
     break;
@@ -2406,6 +2410,9 @@ static int bd_stream_type(AVCodecID codec_id)
   case AV_CODEC_ID_H264:
     stream_type = BLURAY_STREAM_TYPE_VIDEO_H264;
     break;
+  case AV_CODEC_ID_HEVC:
+    stream_type = BLURAY_STREAM_TYPE_VIDEO_HEVC;
+    break;
   case AV_CODEC_ID_MP2:
     stream_type = BLURAY_STREAM_TYPE_AUDIO_MPEG1;
     break;
@@ -2424,6 +2431,9 @@ static int bd_stream_type(AVCodecID codec_id)
   case AV_CODEC_ID_TRUEHD:
     stream_type = BLURAY_STREAM_TYPE_AUDIO_TRUHD;
     break;
+  case AV_CODEC_ID_PCM_BLURAY:
+    stream_type = BLURAY_STREAM_TYPE_AUDIO_LPCM;
+    break;
   case AV_CODEC_ID_HDMV_PGS_SUBTITLE:
     stream_type = BLURAY_STREAM_TYPE_SUB_PG;
     break;
@@ -2478,6 +2488,8 @@ static int bd_video_format(int w, int h, int ilace)
   if( w == 1280 && h ==  720 /* && !ilace*/ ) return BLURAY_VIDEO_FORMAT_720P;
   if( w == 1440 && h == 1080 /* &&  ilace*/ ) return BLURAY_VIDEO_FORMAT_1080I;
   if( w == 1920 && h == 1080 /* && !ilace*/ ) return BLURAY_VIDEO_FORMAT_1080P;
+  if( w == 3840 && h == 2160 &&  !ilace ) return BLURAY_VIDEO_FORMAT_2160P;
+  
   fprintf(stderr, "unknown bluray video format %dx%d %silace\n",
     w, h, !ilace ? "not " : "");
   exit(1);
-- 
2.34.1

