libmix: add a flag indicating whether video decoder buffer contains only one field

BZ: 173283

For some interfaced clips, if video decoder buffer contains
only one field, add a flag to recognize it. Currently it is
only available for AVC.

Change-Id: I90cc291a29626e7bf6b58a042b77c23430da6ba9
Signed-off-by: Tianmi Chen <tianmi.chen@intel.com>
diff --git a/videodecoder/VideoDecoderAVC.cpp b/videodecoder/VideoDecoderAVC.cpp
index c3f3bd4..def0649 100755
--- a/videodecoder/VideoDecoderAVC.cpp
+++ b/videodecoder/VideoDecoderAVC.cpp
@@ -135,10 +135,13 @@
         return DECODE_NO_CONFIG;
     }
 
-    // Don't remove the following codes, it can be enabled for debugging DPB.
-#if 0
+    mVideoFormatInfo.flags = 0;
+    uint32_t fieldFlags = 0;
     for (unsigned int i = 0; i < data->num_pictures; i++) {
         VAPictureH264 &pic = data->pic_data[i].pic_parms->CurrPic;
+        fieldFlags |= pic.flags;
+        // Don't remove the following codes, it can be enabled for debugging DPB.
+#if 0
         VTRACE("%d: decoding frame %.2f, poc top = %d, poc bottom = %d, flags = %d,  reference = %d",
                 i,
                 buffer->timeStamp/1E6,
@@ -147,8 +150,14 @@
                 pic.flags,
                 (pic.flags & VA_PICTURE_H264_SHORT_TERM_REFERENCE) ||
                 (pic.flags & VA_PICTURE_H264_LONG_TERM_REFERENCE));
-    }
 #endif
+    }
+    int32_t topField = fieldFlags & VA_PICTURE_H264_TOP_FIELD;
+    int32_t botField = fieldFlags & VA_PICTURE_H264_BOTTOM_FIELD;
+    if ((topField == 0 && botField != 0) || (topField != 0 && botField == 0)) {
+        mVideoFormatInfo.flags |= IS_SINGLE_FIELD;
+    }
+
     if (data->new_sps || data->new_pps) {
         status = handleNewSequence(data);
         CHECK_STATUS("handleNewSequence");
diff --git a/videodecoder/VideoDecoderDefs.h b/videodecoder/VideoDecoderDefs.h
index fc347ac..c74acf6 100644
--- a/videodecoder/VideoDecoderDefs.h
+++ b/videodecoder/VideoDecoderDefs.h
@@ -110,6 +110,9 @@
 
      // indicate the frame has resolution change
     IS_RESOLUTION_CHANGE = 0x40000,
+
+    // indicate whether video decoder buffer contains only one field
+    IS_SINGLE_FIELD = 0x80000,
 } VIDEO_BUFFER_FLAG;
 
 typedef enum
@@ -216,6 +219,7 @@
     int32_t framerateNom;
     int32_t framerateDenom;
     int32_t actualBufferNeeded;
+    int32_t flags; // indicate whether current picture is field or frame
     VideoExtensionBuffer *ext;
 };