12
12
13
13
using namespace UTILS ;
14
14
15
- AVCCodecHandler::AVCCodecHandler (AP4_SampleDescription* sd)
15
+ AVCCodecHandler::AVCCodecHandler (AP4_SampleDescription* sd, bool isRequiredAnnexB )
16
16
: CodecHandler{sd},
17
17
m_countPictureSetIds{0 },
18
18
m_needSliceInfo{false },
@@ -29,8 +29,16 @@ AVCCodecHandler::AVCCodecHandler(AP4_SampleDescription* sd)
29
29
if (AP4_AvcSampleDescription* avcSampleDescription =
30
30
AP4_DYNAMIC_CAST (AP4_AvcSampleDescription, m_sampleDescription))
31
31
{
32
- m_extraData.SetData (avcSampleDescription->GetRawBytes ().GetData (),
33
- avcSampleDescription->GetRawBytes ().GetDataSize ());
32
+ if (isRequiredAnnexB)
33
+ {
34
+ ExtraDataToAnnexB ();
35
+ }
36
+ else
37
+ {
38
+ m_extraData.SetData (avcSampleDescription->GetRawBytes ().GetData (),
39
+ avcSampleDescription->GetRawBytes ().GetDataSize ());
40
+ }
41
+
34
42
m_countPictureSetIds = avcSampleDescription->GetPictureParameters ().ItemCount ();
35
43
m_naluLengthSize = avcSampleDescription->GetNaluLengthSize ();
36
44
m_needSliceInfo = (m_countPictureSetIds > 1 || width == 0 || height == 0 );
@@ -61,6 +69,26 @@ AVCCodecHandler::AVCCodecHandler(AP4_SampleDescription* sd)
61
69
}
62
70
}
63
71
72
+ bool AVCCodecHandler::CheckExtraData (std::vector<uint8_t >& extraData, bool isRequiredAnnexB)
73
+ {
74
+ if (extraData.empty ())
75
+ return false ;
76
+
77
+ // Make sure that extradata is in the required format
78
+ if (isRequiredAnnexB && !UTILS::IsAnnexB (extraData))
79
+ {
80
+ extraData = UTILS::AvcToAnnexb (extraData);
81
+ return true ;
82
+ }
83
+ if (!isRequiredAnnexB && UTILS::IsAnnexB (extraData))
84
+ {
85
+ extraData = UTILS::AnnexbToAvc (extraData);
86
+ return true ;
87
+ }
88
+
89
+ return false ;
90
+ }
91
+
64
92
bool AVCCodecHandler::ExtraDataToAnnexB ()
65
93
{
66
94
if (AP4_AvcSampleDescription* avcSampleDescription =
@@ -75,29 +103,33 @@ bool AVCCodecHandler::ExtraDataToAnnexB()
75
103
for (unsigned int i{0 }; i < sps.ItemCount (); ++i)
76
104
sz += 4 + sps[i].GetDataSize ();
77
105
78
- m_extraData.SetDataSize (sz);
79
- AP4_Byte* cursor (m_extraData.UseData ());
80
-
81
- for (unsigned int i{0 }; i < sps.ItemCount (); ++i)
82
- {
83
- cursor[0 ] = 0 ;
84
- cursor[1 ] = 0 ;
85
- cursor[2 ] = 0 ;
86
- cursor[3 ] = 1 ;
87
- memcpy (cursor + 4 , sps[i].GetData (), sps[i].GetDataSize ());
88
- cursor += sps[i].GetDataSize () + 4 ;
89
- }
90
- for (unsigned int i{0 }; i < pps.ItemCount (); ++i)
106
+ if (sz > 0 )
91
107
{
92
- cursor[0 ] = 0 ;
93
- cursor[1 ] = 0 ;
94
- cursor[2 ] = 0 ;
95
- cursor[3 ] = 1 ;
96
- memcpy (cursor + 4 , pps[i].GetData (), pps[i].GetDataSize ());
97
- cursor += pps[i].GetDataSize () + 4 ;
108
+ m_extraData.SetDataSize (sz);
109
+ AP4_Byte* cursor (m_extraData.UseData ());
110
+
111
+ for (unsigned int i{0 }; i < sps.ItemCount (); ++i)
112
+ {
113
+ cursor[0 ] = 0 ;
114
+ cursor[1 ] = 0 ;
115
+ cursor[2 ] = 0 ;
116
+ cursor[3 ] = 1 ;
117
+ memcpy (cursor + 4 , sps[i].GetData (), sps[i].GetDataSize ());
118
+ cursor += sps[i].GetDataSize () + 4 ;
119
+ }
120
+ for (unsigned int i{0 }; i < pps.ItemCount (); ++i)
121
+ {
122
+ cursor[0 ] = 0 ;
123
+ cursor[1 ] = 0 ;
124
+ cursor[2 ] = 0 ;
125
+ cursor[3 ] = 1 ;
126
+ memcpy (cursor + 4 , pps[i].GetData (), pps[i].GetDataSize ());
127
+ cursor += pps[i].GetDataSize () + 4 ;
128
+ }
129
+ return true ;
98
130
}
99
- return true ;
100
131
}
132
+
101
133
return false ;
102
134
}
103
135
0 commit comments