mm-dash: CEA fix for UBWC color format

CEA fix for UBWC color format

Change-Id: I645bbec350dabef82f5734679ca7be2e02ad410f
diff --git a/dashplayer/DashPlayer.cpp b/dashplayer/DashPlayer.cpp
index 6c1950a..8f6826f 100644
--- a/dashplayer/DashPlayer.cpp
+++ b/dashplayer/DashPlayer.cpp
@@ -1784,17 +1784,39 @@
             sp<GraphicBuffer> graphicBuffer = static_cast<GraphicBuffer*>(obj.get());
             if (graphicBuffer != NULL)
             {
-              DP_MSG_LOW("kwhatdrainthisbuffer: Extradata present",
-                  "graphicBuffer = %p, width=%d height=%d color-format=%d",
+              size_t filledLen = 0, allocLen = 0;
+              DP_MSG_LOW("kwhatdrainthisbuffer: Extradata present graphicBuffer = %p, width=%d height=%d color-format=%d",
                   graphicBuffer.get(), mCurrentWidth, mCurrentHeight, mColorFormat);
 
               if (mColorFormat == 0x7FA30C04 /*OMX_QCOM_COLOR_FormatYUV420PackedSemiPlanar32m*/)
               {
-                size_t filledLen = (VENUS_Y_STRIDE(COLOR_FMT_NV12, mCurrentWidth)
+                filledLen = (VENUS_Y_STRIDE(COLOR_FMT_NV12, mCurrentWidth)
                                     * VENUS_Y_SCANLINES(COLOR_FMT_NV12, mCurrentHeight))
                                           +  (VENUS_UV_STRIDE(COLOR_FMT_NV12, mCurrentWidth)
                                               * VENUS_UV_SCANLINES(COLOR_FMT_NV12, mCurrentHeight));
-                size_t allocLen = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, mCurrentWidth, mCurrentHeight);
+                allocLen = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, mCurrentWidth, mCurrentHeight);
+              }
+              else if (mColorFormat == 0x7FA30C06 /*QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed*/)
+              {
+                unsigned int y_stride = VENUS_Y_STRIDE(COLOR_FMT_NV12_UBWC, mCurrentWidth);
+                unsigned int uv_stride = VENUS_UV_STRIDE(COLOR_FMT_NV12_UBWC, mCurrentWidth);
+                unsigned int y_sclines = VENUS_Y_SCANLINES(COLOR_FMT_NV12_UBWC, mCurrentHeight);
+                unsigned int uv_sclines = VENUS_UV_SCANLINES(COLOR_FMT_NV12_UBWC, mCurrentHeight);
+                unsigned int y_ubwc_plane = MSM_MEDIA_ALIGN(y_stride * y_sclines, 4096);
+                unsigned int uv_ubwc_plane = MSM_MEDIA_ALIGN(uv_stride * uv_sclines, 4096);
+                unsigned int y_meta_stride = VENUS_Y_META_STRIDE(COLOR_FMT_NV12_UBWC, mCurrentWidth);
+                unsigned int y_meta_scanlines = VENUS_Y_META_SCANLINES(COLOR_FMT_NV12_UBWC, mCurrentHeight);
+                unsigned int y_meta_plane = MSM_MEDIA_ALIGN(y_meta_stride * y_meta_scanlines, 4096);
+                unsigned int uv_meta_stride = VENUS_UV_META_STRIDE(COLOR_FMT_NV12_UBWC, mCurrentWidth);
+                unsigned int uv_meta_scanlines = VENUS_UV_META_SCANLINES(COLOR_FMT_NV12_UBWC, mCurrentHeight);
+                unsigned int uv_meta_plane = MSM_MEDIA_ALIGN(uv_meta_stride * uv_meta_scanlines, 4096);
+
+                filledLen = y_ubwc_plane + uv_ubwc_plane + y_meta_plane + uv_meta_plane;
+                allocLen = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_UBWC, mCurrentWidth, mCurrentHeight);
+              }
+
+              if (filledLen > 0 && allocLen > 0)
+              {
                 size_t offset = buffer->offset();
 
                 DP_MSG_LOW("kwhatdrainthisbuffer: decoded buffer ranges "
@@ -1832,14 +1854,8 @@
                       OMX_QCOM_EXTRADATA_USERDATA *userdata = (OMX_QCOM_EXTRADATA_USERDATA *)pExtra->data;
                       OMX_U8 *data_ptr = (OMX_U8 *)userdata->data;
                       OMX_U32 userdata_size = pExtra->nDataSize - (OMX_U32)sizeof(userdata->type);
-                      if (mCCDecoder != NULL)
-                      {
-                          DP_MSG_HIGH("mCCDecoder->decode %lld",mediaTimeUs);
-                          mCCDecoder->decode(data_ptr, userdata_size, mediaTimeUs);
-                      }
-                      else
-                      {
-                        DP_MSG_LOW(
+
+                      DP_MSG_LOW(
                         "--------------  OMX_ExtraDataMP2UserData Userdata  -------------\n"
                         "    Stream userdata type: %lu\n"
                         "           userdata size: %lu\n"
@@ -1852,9 +1868,16 @@
                             data_ptr[i+2], data_ptr[i+3]);
                         }
 
-                        DP_MSG_LOW(
-                          "-------------- End of OMX_ExtraDataMP2UserData Userdata -----------");
+                      DP_MSG_LOW(
+                        "-------------- End of OMX_ExtraDataMP2UserData Userdata -----------");
 
+                      if (mCCDecoder != NULL)
+                      {
+                          DP_MSG_HIGH("mCCDecoder->decode %lld",mediaTimeUs);
+                          mCCDecoder->decode(data_ptr, userdata_size, mediaTimeUs);
+                      }
+                      else
+                      {
                         /*
                           SEI Syntax
 
diff --git a/dashplayer/DashPlayerDecoder.cpp b/dashplayer/DashPlayerDecoder.cpp
index 3e7b6c0..81d446e 100644
--- a/dashplayer/DashPlayerDecoder.cpp
+++ b/dashplayer/DashPlayerDecoder.cpp
@@ -65,12 +65,12 @@
     mCodecLooper->setName("DashPlayerDecoder-MC");
     mCodecLooper->start(false, false, ANDROID_PRIORITY_AUDIO);
 
-      char property_value[PROPERTY_VALUE_MAX] = {0};
-      property_get("persist.dash.debug.level", property_value, NULL);
+    char property_value[PROPERTY_VALUE_MAX] = {0};
+    property_get("persist.dash.debug.level", property_value, NULL);
 
-      if(*property_value) {
-          mLogLevel = atoi(property_value);
-      }
+    if(*property_value) {
+        mLogLevel = atoi(property_value);
+    }
 }
 
 DashPlayer::Decoder::~Decoder() {
@@ -633,7 +633,6 @@
     if (mData1 >= 0x10 && mData1 <= 0x1f)
     {
       *channel = (mData1 >= 0x18 ? 1 : 0) + (mType ? 2 : 0);
-      ALOGE("CCDecoder: getChannel %d", *channel);
       return true;
     }
     return false;
@@ -653,6 +652,13 @@
   {
     mTrackIndices[i] = -1;
   }
+
+  char property_value[PROPERTY_VALUE_MAX] = {0};
+  property_get("persist.dash.debug.level", property_value, NULL);
+
+  if(*property_value) {
+      mLogLevel = atoi(property_value);
+  }
 }
 
 
@@ -749,7 +755,7 @@
 {
   if (!isTrackValid(index))
   {
-    ALOGE("CCDecoder: getTrackInfo - NotValid track");
+    DPD_MSG_ERROR("CCDecoder: getTrackInfo - NotValid track");
     return NULL;
   }
 
@@ -773,27 +779,27 @@
 {
   if (!isTrackValid(index))
   {
-    ALOGE("CCDecoder: selectTrack - NotValid track");
+    DPD_MSG_ERROR("CCDecoder: selectTrack - NotValid track");
     return BAD_VALUE;
   }
   if (select)
   {
     if (mSelectedTrack == (ssize_t)index)
     {
-      ALOGV("CCDecoder: track %zu already selected", index);
+      DPD_MSG_HIGH("CCDecoder: track %zu already selected", index);
       return BAD_VALUE;
     }
-    ALOGV("CCDecoder: selected track %zu", index);
+    DPD_MSG_HIGH("CCDecoder: selected track %zu", index);
     mSelectedTrack = index;
   }
   else
   {
     if (mSelectedTrack != (ssize_t)index)
     {
-      ALOGV("CCDecoder: track %zu is not selected", index);
+      DPD_MSG_ERROR("CCDecoder: track %zu is not selected", index);
       return BAD_VALUE;
     }
-    ALOGV("CCDecoder: unselected track %zu", index);
+    DPD_MSG_HIGH("CCDecoder: unselected track %zu", index);
     mSelectedTrack = -1;
   }
   return OK;
@@ -845,7 +851,7 @@
      bool process_cc_data_flag = br.getBits(1);
      br.skipBits(1); //additional_data_flag
      size_t cc_count = br.getBits(5);
-     ALOGV("CCDecoder: CEA CC cc_count : %d",cc_count);
+     DPD_MSG_HIGH("CCDecoder: CEA CC cc_count : %d",cc_count);
      br.skipBits(8); // em_data;
 
      if (process_cc_data_flag)
@@ -855,7 +861,6 @@
 
        for (size_t i = 0; i < cc_count; i++)
        {
-         ALOGV("CCDecoder: Processing cc_data_pkt #: %d",i);
          uint8_t marker = br.getBits(5);
          CHECK_EQ(marker, 0x1f);
          bool cc_valid = br.getBits(1);
@@ -863,7 +868,7 @@
          //PrintCCTypeCombo(cc_valid, cc_type);
          uint8_t cc_data_1 = br.getBits(8) & 0x7f;
          uint8_t cc_data_2 = br.getBits(8) & 0x7f;
-         ALOGV("CCDecoder: cc_data_1 0x%x cc_data_2 0x%x", cc_data_1, cc_data_2);
+         DPD_MSG_HIGH("CCDecoder: Processing cc_data_pkt #: %d cc_data_1 0x%x cc_data_2 0x%x", i, cc_data_1, cc_data_2);
          //If field “x” Buffer is empty at the transmit time of NTSC field “x”, a CEA-608 waveform should be
          //generated for that field with cc_data_1 = 0x80 and cc_data_2 = 0x80
          //in CEA-608 notation, two 0x00s with odd parity,remove odd parity bit
@@ -879,7 +884,7 @@
                   mTrackIndices[channel] = mFoundChannels.size();
                   mFoundChannels.push_back(channel);
                   trackAdded = true;
-                  ALOGE("CCDecoder: CEA TrackAdded successfully");
+                  DPD_MSG_HIGH("CCDecoder: CEA TrackAdded successfully - channel %d index %d", channel,  mTrackIndices[channel]);
              }
              memcpy(ccBuf->data() + ccBuf->size(),(void *)&cc, sizeof(cc));
              ccBuf->setRange(0, ccBuf->size() + sizeof(CCData));
@@ -887,21 +892,21 @@
            }
            else
            {
-             ALOGW("CCDecoder: CEA null pad %d", i);
+             DPD_MSG_HIGH("CCDecoder: CEA null pad %d", i);
            }
          }
          else
          {
-            ALOGV("CCDecoder: CEA-708 cc_valid %d cc_type %d", cc_valid, cc_type);
+            DPD_MSG_HIGH("CCDecoder: CEA-708 cc_valid %d cc_type %d", cc_valid, cc_type);
          }
        }
-       ALOGV("CCDecoder: mCCMap.add timeUs %lld ccBuf.size() %d", mediaTimeUs , ccBuf->size());
+       DPD_MSG_HIGH("CCDecoder: mCCMap.add timeUs %lld ccBuf.size() %d", mediaTimeUs , ccBuf->size());
        //printmCCMap();
      }
   }
   else
   {
-    ALOGE("CCDecoder: Malformed SEI payload type 4");
+    DPD_MSG_ERROR("CCDecoder: Malformed SEI payload type 4");
   }
   return trackAdded;
 }
@@ -935,7 +940,7 @@
 {
   if (extractPictureUserData(pictureUserData, pictureUserDataSize, mediaTimeUs))
   {
-    ALOGV("CCDecoder: Found CEA-608 track");
+    DPD_MSG_ERROR("CCDecoder: Found CEA-608 track");
     if (mNotify != NULL)
     {
       sp<AMessage> msg = mNotify->dup();
@@ -945,22 +950,21 @@
   }
 }
 
-
 void DashPlayer::CCDecoder::display(int64_t timeUs)
 {
   if (!isTrackValid(mSelectedTrack))
   {
-    ALOGE("CCDecoder: display Could not find current track(index=%d)", mSelectedTrack);
+    DPD_MSG_ERROR("CCDecoder: display Could not find current track(index=%d)", mSelectedTrack);
     return;
   }
 
   ssize_t index = mCCMap.indexOfKey(timeUs);
   if (index < 0)
   {
-    ALOGE("CCDecoder: display cc for timestamp %lld not found", timeUs);
+    DPD_MSG_ERROR("CCDecoder: display cc for timestamp %lld not found", timeUs);
     return;
   }
-  ALOGI("CCDecoder: display found TS %lld at index %d", timeUs, index);
+  DPD_MSG_ERROR("CCDecoder: display found TS %lld at index %d", timeUs, index);
   //printmCCMap();
   sp<ABuffer> ccBuf = filterCCBuf(mCCMap.valueAt(index), mSelectedTrack);
 
@@ -980,7 +984,7 @@
   }
   else
   {
-    ALOGE("CCDecoder: ccBuf->size() is zero");
+    DPD_MSG_ERROR("CCDecoder: ccBuf->size() is zero");
   }
   // remove all entries before timeUs
   mCCMap.removeItemsAt(0, index + 1);
@@ -992,31 +996,55 @@
 
 void DashPlayer::CCDecoder::PrintCCTypeCombo(bool cc_valid, uint8_t cc_type)
 {
-  ALOGE("CCDecoder: cc_valid %d and cc_type %d",cc_valid, cc_type);
+  DPD_MSG_MEDIUM("CCDecoder: cc_valid %d and cc_type %d",cc_valid, cc_type);
   if (cc_valid)
   {
-    if(cc_type == 0 ) ALOGW("CEA-608 line 21 field 1 CC bytes");
-    else if(cc_type == 1 ) ALOGW("CEA-608 line 21 field 2 CC bytes");
-    else if(cc_type == 2 ) ALOGW("Continuing CCP: cc_data_1/cc_data_2 CCP data");
-    else if(cc_type == 3 ) ALOGW("start CCP: cc_data_1 CCP Header and cc_data_2 CCP data ");
+    if(cc_type == 0 )
+    {
+      DPD_MSG_MEDIUM("CEA-608 line 21 field 1 CC bytes");
+    }
+    else if(cc_type == 1 )
+    {
+      DPD_MSG_MEDIUM("CEA-608 line 21 field 2 CC bytes");
+    }
+    else if(cc_type == 2 )
+    {
+      DPD_MSG_MEDIUM("Continuing CCP: cc_data_1/cc_data_2 CCP data");
+    }
+    else if(cc_type == 3 )
+    {
+      DPD_MSG_MEDIUM("start CCP: cc_data_1 CCP Header and cc_data_2 CCP data ");
+    }
   }
   else
   {
-    if(cc_type == 0 ) ALOGW("CEA-608 line 21 field 1 - DTVCC padding bytes");
-    else if(cc_type == 1 ) ALOGW("CEA-608 line 21 field 2 - DTVCC padding bytes");
-    else if(cc_type == 2 ) ALOGW("DTV CC padding bytes");
-    else if(cc_type == 3 ) ALOGW("DTV CC padding bytes");
+    if(cc_type == 0 )
+    {
+      DPD_MSG_MEDIUM("CEA-608 line 21 field 1 - DTVCC padding bytes");
+    }
+    else if(cc_type == 1 )
+    {
+      DPD_MSG_MEDIUM("CEA-608 line 21 field 2 - DTVCC padding bytes");
+    }
+    else if(cc_type == 2 )
+    {
+      DPD_MSG_MEDIUM("DTV CC padding bytes");
+    }
+    else if(cc_type == 3 )
+    {
+      DPD_MSG_MEDIUM("DTV CC padding bytes");
+    }
   }
 }
 
 void DashPlayer::CCDecoder::printmCCMap()
 {
-  ALOGV("CCDecoder: printmCCMap size %d ", mCCMap.size());
+  DPD_MSG_HIGH("CCDecoder: printmCCMap size %d ", mCCMap.size());
   for (size_t i = 0; i < mCCMap.size(); ++i)
   {
     const sp<ABuffer> ccBuf =  mCCMap.valueAt(i);
     const int64_t timeUs = mCCMap.keyAt(i);
-    ALOGV("CCDecoder: CCMap[%d] ccBuf size %d and timeTs %lld", i, ccBuf->size(),timeUs );
+    DPD_MSG_HIGH("CCDecoder: CCMap[%d] ccBuf size %d and timeTs %lld", i, ccBuf->size(),timeUs );
   }
 }
 
diff --git a/dashplayer/DashPlayerDecoder.h b/dashplayer/DashPlayerDecoder.h
index 5682b34..e21d0f5 100644
--- a/dashplayer/DashPlayerDecoder.h
+++ b/dashplayer/DashPlayerDecoder.h
@@ -139,6 +139,7 @@
     int32_t mCurrentHeight;
     int32_t mColorFormat;
 
+    int mLogLevel;
 
     DISALLOW_EVIL_CONSTRUCTORS(CCDecoder);
 };
diff --git a/dashplayer/DashPlayerRenderer.cpp b/dashplayer/DashPlayerRenderer.cpp
index 3e283be..3b73318 100644
--- a/dashplayer/DashPlayerRenderer.cpp
+++ b/dashplayer/DashPlayerRenderer.cpp
@@ -408,7 +408,7 @@
                 continue;
             }
 
-            DPR_MSG_HIGH("rendering audio at media time %.2f secs", (double)mediaTimeUs / 1E6);
+            DPR_MSG_ERROR("rendering audio at media time %.2f secs", (double)mediaTimeUs / 1E6);
 
             mAnchorTimeMediaUs = mediaTimeUs;
 
@@ -425,6 +425,9 @@
 
             mAnchorTimeRealUs =
                 ALooper::GetNowUs() + realTimeOffsetUs;
+
+            DPR_MSG_HIGH("onDrainAudioQueue mediaTimeUs %lld us mAnchorTimeMediaUs %lld us mAnchorTimeRealUs %lld us",
+             mediaTimeUs, mAnchorTimeMediaUs, mAnchorTimeRealUs);
         }
 
         size_t copy = entry->mBuffer->size() - entry->mOffset;
@@ -524,7 +527,7 @@
 
             delayUs = realTimeUs - ALooper::GetNowUs();
             if (delayUs > 0) {
-                DPR_MSG_ERROR("postDrainVideoQueue video early by %.2f secs", (double)delayUs / 1E6);
+                DPR_MSG_HIGH("postDrainVideoQueue video early by %.2f secs", (double)delayUs / 1E6);
             }
         }
     }
@@ -568,6 +571,9 @@
     int64_t nowUs = ALooper::GetNowUs();
     mVideoLateByUs = nowUs - realTimeUs;
 
+    DPR_MSG_HIGH("onDrainVideoQueue mediaTimeUs %lld us mAnchorTimeMediaUs %lld us mAnchorTimeRealUs %lld us",
+             mediaTimeUs, mAnchorTimeMediaUs, mAnchorTimeRealUs);
+
     bool tooLate = (mVideoLateByUs > mAVSyncDelayWindowUs);
 
     if (tooLate && (!mHasAudio || (mediaTimeUs > mAnchorTimeMediaUs)))
@@ -579,13 +585,13 @@
     }
 
     if (tooLate) {
-        DPR_MSG_HIGH("video late by %lld us (%.2f secs)",
+        DPR_MSG_ERROR("video late by %lld us (%.2f secs)",
              mVideoLateByUs, (double)mVideoLateByUs / 1E6);
         if(mStats != NULL) {
             mStats->recordLate(realTimeUs,nowUs,mVideoLateByUs,mAnchorTimeRealUs);
         }
     } else {
-        DPR_MSG_HIGH("rendering video at media time %.2f secs", (double)mediaTimeUs / 1E6);
+        DPR_MSG_ERROR("rendering video at media time %.2f secs", (double)mediaTimeUs / 1E6);
         if(mStats != NULL) {
             mStats->recordOnTime(realTimeUs,nowUs,mVideoLateByUs);
             mStats->incrementTotalRenderingFrames();