---
 libavcodec/mpeg12dec.c |   69 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 57 insertions(+), 12 deletions(-)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index d9b49f3..db675f1 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -27,6 +27,7 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/internal.h"
+#include "libavutil/stereo3d.h"
 #include "internal.h"
 #include "avcodec.h"
 #include "dsputil.h"
@@ -2026,18 +2027,62 @@ static void mpeg_decode_user_data(AVCodecContext *avctx,
     const uint8_t *buf_end = p + buf_size;
 
     /* we parse the DTG active format information */
-    if (buf_end - p >= 5 &&
-        p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
-        int flags = p[4];
-        p += 5;
-        if (flags & 0x80) {
-            /* skip event id */
-            p += 2;
-        }
-        if (flags & 0x40) {
-            if (buf_end - p < 1)
-                return;
-            avctx->dtg_active_format = p[0] & 0x0f;
+    if (buf_end - p >= 5) {
+        if (p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
+            int flags = p[4];
+            p += 5;
+            if (flags & 0x80) {
+                /* skip event id */
+                p += 2;
+            }
+            if (flags & 0x40) {
+                if (buf_end - p < 1)
+                    return;
+                avctx->dtg_active_format = p[0] & 0x0f;
+            }
+        } else if (p[0] == 'J' && p[1] == 'P' && p[2] == '3' && p[3] == 'D') {
+            Mpeg1Context *s1  = avctx->priv_data;
+            MpegEncContext *s = &s1->mpeg_enc_ctx;
+            AVFrameSideData *side_data;
+            AVStereo3D stereo;
+
+            if (p[4] == 0x03) { // S3D_video_format_length
+                // the mask ignores reserved_bit
+                const uint8_t S3D_video_format_type = p[5] & 0x7F;
+                stereo.info = AV_STEREO3D_NORMAL;
+
+                switch (S3D_video_format_type) {
+                case 0x03:
+                    stereo.type = AV_STEREO3D_SIDEBYSIDE;
+                    break;
+                case 0x04:
+                    stereo.type = AV_STEREO3D_TOPBOTTOM;
+                    break;
+                case 0x08:
+                    stereo.type = AV_STEREO3D_NOT_REALLY;
+                    break;
+                case 0x23:
+                    stereo.type = AV_STEREO3D_SIDEBYSIDE;
+                    stereo.info |= AV_STEREO3D_QUINCUNX;
+                    break;
+                default:
+                    stereo.type = AV_STEREO3D_NONE;
+                    break;
+                }
+
+                if (s->current_picture_ptr && stereo.type != AV_STEREO3D_NONE) 
{
+                    if (stereo.type != AV_STEREO3D_NOT_REALLY)
+                        stereo.info |= AV_STEREO3D_SIZE_HALF;
+
+                    side_data = 
av_frame_new_side_data(&s->current_picture_ptr->f,
+                                                       AV_FRAME_DATA_STEREO3D,
+                                                       sizeof(AVStereo3D));
+                    if (!side_data)
+                        return;
+
+                    memcpy(side_data->data, &stereo, sizeof(AVStereo3D));
+                }
+            }
         }
     }
 }
-- 
1.7.9.5

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to