aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-multimedia/gstreamer/gst-plugins-ugly/0001-asfdemux-asfpacket-set-frame-start-code-to-VC-1-adva.patch
blob: d065c7c47a229804eeea9d009a4a0ff91eb02abf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
From 258bf9862e5b7179562f0cae9fb470f6486dca3a Mon Sep 17 00:00:00 2001
From: Kazunori Kobayashi <kkobayas@igel.co.jp>
Date: Thu, 12 Jul 2012 12:08:15 +0900
Subject: [PATCH] asfdemux/asfpacket: set frame start code to VC-1 advanced
 profile stream

VC-1 advanced profile constrains the bitstream format to pair
the frame data with the frame start code.
---
 gst/asfdemux/asfpacket.c |   36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/gst/asfdemux/asfpacket.c b/gst/asfdemux/asfpacket.c
index 552a559..77209f1 100644
--- a/gst/asfdemux/asfpacket.c
+++ b/gst/asfdemux/asfpacket.c
@@ -71,9 +71,10 @@ asf_packet_read_varlen_int (guint lentype_flags, guint lentype_bit_offset,
 
 static GstBuffer *
 asf_packet_create_payload_buffer (AsfPacket * packet, const guint8 ** p_data,
-    guint * p_size, guint payload_len)
+    guint * p_size, guint payload_len, gboolean need_st_code)
 {
   guint off;
+  guint8 *st_code;
 
   g_assert (payload_len <= *p_size);
 
@@ -83,6 +84,21 @@ asf_packet_create_payload_buffer (AsfPacket * packet, const guint8 ** p_data,
   *p_data += payload_len;
   *p_size -= payload_len;
 
+  /* set start code for VC-1 advanced profile */
+  if (need_st_code && off >= 4) {
+    st_code = GST_BUFFER_DATA (packet->buf) + (off - 4);
+    /* check if this packet has a start code */
+    if (st_code[4] != 0x00 || st_code[5] != 0x00 || st_code[6] != 0x01 ||
+        st_code[7] != 0x0d) {
+      st_code[0] = 0x00;
+      st_code[1] = 0x00;
+      st_code[2] = 0x01;
+      st_code[3] = 0x0d;
+
+      return gst_buffer_create_sub (packet->buf, off - 4, payload_len + 4);
+    }
+  }
+
   return gst_buffer_create_sub (packet->buf, off, payload_len);
 }
 
@@ -274,6 +290,9 @@ gst_asf_demux_parse_payload (GstASFDemux * demux, AsfPacket * packet,
   gboolean is_compressed;
   guint payload_len;
   guint stream_num;
+  GstStructure *structure;
+  guint32 fourcc;
+  gboolean need_st_code = FALSE;
 
   if (G_UNLIKELY (*p_size < 1)) {
     GST_WARNING_OBJECT (demux, "Short packet!");
@@ -353,6 +372,17 @@ gst_asf_demux_parse_payload (GstASFDemux * demux, AsfPacket * packet,
     return TRUE;
   }
 
+  structure = gst_caps_get_structure (stream->caps, 0);
+  if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
+    /*
+     * set start code for VC-1 advanced profile if fourcc is 'WVC1' and this
+     * packet is at the head of a payload.
+     */
+    if (fourcc == GST_MAKE_FOURCC ('W', 'V', 'C', '1')
+        && payload.mo_offset == 0)
+      need_st_code = TRUE;
+  }
+
   if (G_UNLIKELY (!is_compressed)) {
     GST_LOG_OBJECT (demux, "replicated data length: %u", payload.rep_data_len);
 
@@ -384,7 +414,7 @@ gst_asf_demux_parse_payload (GstASFDemux * demux, AsfPacket * packet,
     if ((stream = gst_asf_demux_get_stream (demux, stream_num))
         && payload_len) {
       payload.buf = asf_packet_create_payload_buffer (packet, p_data, p_size,
-          payload_len);
+          payload_len, need_st_code);
 
       /* n-th fragment of a fragmented media object? */
       if (payload.mo_offset != 0) {
@@ -443,7 +473,7 @@ gst_asf_demux_parse_payload (GstASFDemux * demux, AsfPacket * packet,
 
       if (G_LIKELY (sub_payload_len > 0)) {
         payload.buf = asf_packet_create_payload_buffer (packet,
-            &payload_data, &payload_len, sub_payload_len);
+            &payload_data, &payload_len, sub_payload_len, need_st_code);
 
         payload.ts = ts;
         if (G_LIKELY (ts_delta))
-- 
1.7.9.5