[M120 Migration] Support HDR10+ property 68/308268/4
authorwuxiaoliang <xliang.wu@samsung.com>
Mon, 18 Mar 2024 08:24:57 +0000 (16:24 +0800)
committerBot Blink <blinkbot@samsung.com>
Tue, 26 Mar 2024 03:52:40 +0000 (03:52 +0000)
upstream remove side_data_size and add struct DecoderBufferSideData in this patch:
https://chromium-review.googlesource.com/c/chromium/src/+/4757645

Migrated from:
https://review.tizen.org/gerrit/#/c/platform/framework/web/chromium-efl/+/290546/

Change-Id: I0abc0b4fdd7d708582eb9215710ceb51ea194a2d
Signed-off-by: wuxiaoliang <xliang.wu@samsung.com>
tizen_src/chromium_impl/media/filters/media_player_esplusplayer_tv.cc
tizen_src/chromium_impl/media/filters/media_player_esplusplayer_tv.h

index 33d2e73..84361c1 100644 (file)
@@ -111,8 +111,16 @@ int MediaPlayerESPlusPlayerTV::SetVideoStreamInfo(
     }
   }
 
-  LOG(INFO) << "Framerate: [" << video_stream_info.framerate_num << "] ["
-            << video_stream_info.framerate_den << "]";
+  video_codec_ = video_config.codec();
+  if (hdr_info_.compare(video_config.hdr_info()) != 0) {
+    is_hdr_changed_ = true;
+    hdr_info_ = video_config.hdr_info();
+  }
+
+  LOG_ID(INFO, player_id_) << "Framerate: [" << video_stream_info.framerate_num
+                           << "] [" << video_stream_info.framerate_den << "]"
+                           << " ,is_hdr_changed_  : " << is_hdr_changed_
+                           << " ,hdr info:" << hdr_info_;
 
   if (!SetVideoSubmitDataType(video_config)) {
     LOG(ERROR) << "SetVideoSubmitDataType failed.";
@@ -243,6 +251,7 @@ esplusplayer_submit_status MediaPlayerESPlusPlayerTV::SubmitEsPacket(
 
     // This filed only set when PushMediaPacket
     packet.matroska_color_info = nullptr;
+    FillHDRIntoPacket(type, buffer, &packet);
 
     unsigned int tz_handle = buffer->tz_handle() ? buffer->tz_handle() : 0;
 #if TIZEN_VERSION_AT_LEAST(6, 0, 0)
@@ -431,4 +440,127 @@ esplusplayer_drm_info* MediaPlayerESPlusPlayerTV::DrmInfo::GetPlayerDrmInfo(
 }
 #endif
 
+void MediaPlayerESPlusPlayerTV::HDRStringToMatroskaColor(
+    const std::string& hdr_info,
+    esplusplayer_matroska_color* matroska_color) {
+  const char* fmt =
+      "matrixCoefficients:%u bitsPerChannel:%u chromaSubsamplingHorz:%u "
+      "chromaSubsamplingVert:%u"
+      " cbSubsamplingHorz:%u cbSubsamplingVert:%u chromaSitingHorz:%u "
+      "chromaSitingVert:%u"
+      " range:%u transferCharacteristics:%u primaries:%u maxCLL:%u maxFALL:%u"
+      " RX:%lf RY:%lf GX:%lf GY:%lf BX:%lf BY:%lf wX:%lf wY:%lf"
+      " luminanceMax:%lf luminanceMin:%lf";
+
+  memset(matroska_color, 0, sizeof(esplusplayer_matroska_color));
+  if (sscanf(hdr_info.c_str(), fmt, &(matroska_color->matrix_coefficients),
+             &(matroska_color->bits_per_channel),
+             &(matroska_color->chroma_subsampling_horizontal),
+             &(matroska_color->chroma_subsampling_vertical),
+             &(matroska_color->cb_subsampling_horizontal),
+             &(matroska_color->cb_subsampling_vertical),
+             &(matroska_color->chroma_siting_horizontal),
+             &(matroska_color->chroma_siting_vertical),
+             &(matroska_color->range),
+             &(matroska_color->transfer_characteristics),
+             &(matroska_color->primaries), &(matroska_color->max_cll),
+             &(matroska_color->max_fall),
+             &(matroska_color->metadata.primary_r_chromaticity_x),
+             &(matroska_color->metadata.primary_r_chromaticity_y),
+             &(matroska_color->metadata.primary_g_chromaticity_x),
+             &(matroska_color->metadata.primary_g_chromaticity_y),
+             &(matroska_color->metadata.primary_b_chromaticity_x),
+             &(matroska_color->metadata.primary_b_chromaticity_y),
+             &(matroska_color->metadata.white_point_chromaticity_x),
+             &(matroska_color->metadata.white_point_chromaticity_y),
+             &(matroska_color->metadata.luminance_max),
+             &(matroska_color->metadata.luminance_min)) != 23) {
+    LOG(ERROR) << "HDRStringToMatroskaColor hdr string invalid. " << hdr_info;
+    return;
+  }
+
+  LOG_ID(INFO, player_id_)
+      << "matrixCoefficients:" << matroska_color->matrix_coefficients
+      << " bitsPerChannel:" << matroska_color->bits_per_channel
+      << " chromaSubsamplingHorz:"
+      << matroska_color->chroma_subsampling_horizontal
+      << " chromaSubsamplingVert:"
+      << matroska_color->chroma_subsampling_vertical
+      << " cbSubsamplingHorz:" << matroska_color->cb_subsampling_horizontal
+      << " cbSubsamplingVert:" << matroska_color->cb_subsampling_vertical
+      << " chromaSitingHorz:" << matroska_color->chroma_siting_horizontal
+      << " chromaSitingVert:" << matroska_color->chroma_siting_vertical
+      << " range:" << matroska_color->range
+      << " transferCharacteristics:" << matroska_color->transfer_characteristics
+      << " primaries:" << matroska_color->primaries
+      << " maxCLL:" << matroska_color->max_cll
+      << " maxFALL:" << matroska_color->max_fall
+      << " RX:" << matroska_color->metadata.primary_r_chromaticity_x
+      << " RY:" << matroska_color->metadata.primary_r_chromaticity_y
+      << " GX:" << matroska_color->metadata.primary_g_chromaticity_x
+      << " GY:" << matroska_color->metadata.primary_g_chromaticity_y
+      << " BX:" << matroska_color->metadata.primary_b_chromaticity_x
+      << " BY:" << matroska_color->metadata.primary_b_chromaticity_y
+      << " wX:" << matroska_color->metadata.white_point_chromaticity_x
+      << " wY:" << matroska_color->metadata.white_point_chromaticity_y
+      << " luminanceMax:" << matroska_color->metadata.luminance_max
+      << " luminanceMin:" << matroska_color->metadata.luminance_min;
+}
+
+void MediaPlayerESPlusPlayerTV::FillHDRIntoPacket(
+    DemuxerStream::Type type,
+    scoped_refptr<DecoderBuffer> buffer,
+    esplusplayer_es_packet* packet) {
+  if (type != media::DemuxerStream::VIDEO)
+    return;
+
+  if (!buffer) {
+    LOG_ID(ERROR, player_id_)
+        << "decoder buffer is null, cannot get HDR10 metadata";
+    return;
+  }
+
+  // update HDR info in the first packet
+  if (is_hdr_changed_) {
+    HDRStringToMatroskaColor(hdr_info_, &matroska_color_);
+    packet->matroska_color_info = &matroska_color_;
+    is_hdr_changed_ = false;
+  }
+
+  if (!buffer->has_side_data()) {
+    LOG_ID(ERROR, player_id_) << "decoder buffer has no side data";
+    return;
+  }
+
+  if (buffer->side_data()->alpha_data.empty()) {
+    LOG_ID(ERROR, player_id_) << "decoder buffer has no alpha data";
+    return;
+  }
+
+  uint8_t* side_data = (uint8_t*)buffer->side_data()->alpha_data.data();
+  size_t side_data_size = buffer->side_data()->alpha_data.size();
+
+  if (side_data_size > 8) {
+    // follow cobalt's check about hdr10plus inf
+    std::vector<uint8_t> side_data_vec;
+    size_t side_data_vec_size = 0;
+    uint64_t blockAddId = 0;
+    for (int j = 0; j < 8; ++j) {
+      blockAddId = (blockAddId << 8) | side_data[j];
+    }
+
+    if (blockAddId == 0x04) {
+      side_data_vec_size = side_data_size - 8;
+      side_data_vec.resize(side_data_vec_size);
+      memcpy(&side_data_vec[0], side_data + 8,
+             sizeof(uint8_t) * side_data_vec_size);
+    }
+
+    packet->hdr10p_metadata_size = side_data_vec_size;
+    packet->hdr10p_metadata =
+        reinterpret_cast<char*>(const_cast<uint8_t*>(side_data_vec.data()));
+    matroska_color_.isHDR10p = true;
+  }
+}
+
 }  // namespace media
index a063bbf..4a9d6c6 100644 (file)
@@ -98,6 +98,17 @@ class MEDIA_EXPORT MediaPlayerESPlusPlayerTV : public MediaPlayerESPlusPlayer {
   bool is_video_drm_eme_{false};
   bool single_process_mode_{false};
   media::VideoCodec video_codec_{media::VideoCodec::kUnknown};
+
+  void HDRStringToMatroskaColor(const std::string& hdr_info,
+                                esplusplayer_matroska_color* matroska_color);
+  void FillHDRIntoPacket(DemuxerStream::Type type,
+                         scoped_refptr<DecoderBuffer> buffer,
+                         esplusplayer_es_packet* packet);
+
+  std::string hdr_info_;
+  bool is_hdr_changed_{false};
+  esplusplayer_matroska_color matroska_color_;
+
   base::WeakPtrFactory<MediaPlayerESPlusPlayerTV> weak_factory_{this};
 };
 }  // namespace media