@@ -75,7 +75,6 @@ class MJPEG2RGB : public pixel_format_base
75
75
m_avframe_device(av_frame_alloc()),
76
76
m_avframe_rgb(av_frame_alloc()),
77
77
m_avoptions(NULL ),
78
- m_avpacket(av_packet_alloc()),
79
78
m_averror_str(reinterpret_cast <char *>(malloc(AV_ERROR_MAX_STRING_SIZE)))
80
79
{
81
80
if (!m_avcodec) {
@@ -85,9 +84,6 @@ class MJPEG2RGB : public pixel_format_base
85
84
if (!m_avparser) {
86
85
throw std::runtime_error (" Could not find MJPEG parser" );
87
86
}
88
- if (!m_avpacket) {
89
- throw std::runtime_error (" Could not allocate AVPacket" );
90
- }
91
87
92
88
m_avcodec_context = avcodec_alloc_context3 (m_avcodec);
93
89
@@ -151,9 +147,6 @@ class MJPEG2RGB : public pixel_format_base
151
147
if (m_avoptions) {
152
148
free (m_avoptions);
153
149
}
154
- if (m_avpacket) {
155
- free (m_avpacket);
156
- }
157
150
if (m_avcodec_context) {
158
151
avcodec_close (m_avcodec_context);
159
152
avcodec_free_context (&m_avcodec_context);
@@ -179,18 +172,14 @@ class MJPEG2RGB : public pixel_format_base
179
172
// clear the picture
180
173
memset (dest, 0 , m_avframe_device_size);
181
174
182
- #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 133, 100)
183
- // deprecated: https://github.com/FFmpeg/FFmpeg/commit/f7db77bd8785d1715d3e7ed7e69bd1cc991f2d07
184
- av_init_packet (m_avpacket);
185
- #endif
186
-
187
- av_packet_from_data (
188
- m_avpacket,
189
- const_cast <uint8_t *>(reinterpret_cast <const uint8_t *>(src)),
190
- bytes_used);
175
+ auto avpacket = av_packet_alloc ();
176
+ av_new_packet (avpacket, bytes_used);
177
+ memcpy (avpacket->data , src, bytes_used);
191
178
192
179
// Pass src MJPEG image to decoder
193
- m_result = avcodec_send_packet (m_avcodec_context, m_avpacket);
180
+ m_result = avcodec_send_packet (m_avcodec_context, avpacket);
181
+
182
+ av_packet_free (&avpacket);
194
183
195
184
// If result is not 0, report what went wrong
196
185
if (m_result != 0 ) {
@@ -234,7 +223,6 @@ class MJPEG2RGB : public pixel_format_base
234
223
AVFrame * m_avframe_device;
235
224
AVFrame * m_avframe_rgb;
236
225
AVDictionary * m_avoptions;
237
- AVPacket * m_avpacket;
238
226
SwsContext * m_sws_context;
239
227
size_t m_avframe_device_size;
240
228
size_t m_avframe_rgb_size;
0 commit comments