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
100
101
|
--- a/osdk-core/advanced-sensing/camera_stream/src/dji_camera_stream_decoder.hpp
+++ b/osdk-core/advanced-sensing/camera_stream/src/dji_camera_stream_decoder.hpp
@@ -13,6 +13,7 @@
extern "C"{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
+#include <libavutil/imgutils.h>
#include <libswscale/swscale.h>
}
@@ -52,7 +53,7 @@
pthread_mutex_t decodemutex;
AVCodecContext* pCodecCtx;
- AVCodec* pCodec;
+ const AVCodec* pCodec;
AVCodecParserContext* pCodecParserCtx;
SwsContext* pSwsCtx;
--- a/osdk-core/advanced-sensing/camera_stream/src/dji_camera_stream_decoder.cpp
+++ b/osdk-core/advanced-sensing/camera_stream/src/dji_camera_stream_decoder.cpp
@@ -67,7 +67,6 @@
return true;
}
- avcodec_register_all();
pCodecCtx = avcodec_alloc_context3(NULL);
if (!pCodecCtx)
{
@@ -130,7 +129,7 @@
if (NULL != pFrameYUV)
{
- av_free(pFrameYUV);
+ av_frame_free(&pFrameYUV);
pFrameYUV = NULL;
}
@@ -140,16 +139,10 @@
pCodecParserCtx = NULL;
}
- if (NULL != pCodec)
- {
- avcodec_close(pCodecCtx);
- pCodec = NULL;
- }
-
if (NULL != pCodecCtx)
{
- av_free(pCodecCtx);
- pCodecCtx = NULL;
+ avcodec_free_context(&pCodecCtx);
+ pCodec = NULL;
}
if (NULL != rgbBuf )
@@ -160,7 +153,7 @@
if (NULL != pFrameRGB)
{
- av_free(pFrameRGB);
+ av_frame_free(&pFrameRGB);
pFrameRGB = NULL;
}
@@ -219,7 +212,12 @@
if (pkt.size > 0)
{
int gotPicture = 0;
- avcodec_decode_video2(pCodecCtx, pFrameYUV, &gotPicture, &pkt);
+ int ret = avcodec_send_packet(pCodecCtx, &pkt);
+ if (ret >= 0)
+ {
+ ret = avcodec_receive_frame(pCodecCtx, pFrameYUV);
+ gotPicture = (ret == 0) ? 1 : 0;
+ }
if (!gotPicture)
{
@@ -241,9 +239,9 @@
if(NULL == rgbBuf)
{
- bufSize = avpicture_get_size(AV_PIX_FMT_RGB24, w, h);
+ bufSize = av_image_get_buffer_size(AV_PIX_FMT_RGB24, w, h, 1);
rgbBuf = (uint8_t*) av_malloc(bufSize);
- avpicture_fill((AVPicture*)pFrameRGB, rgbBuf, AV_PIX_FMT_RGB24, w, h);
+ av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, rgbBuf, AV_PIX_FMT_RGB24, w, h, 1);
}
if(NULL != pSwsCtx && NULL != rgbBuf)
@@ -261,7 +259,7 @@
}
}
pthread_mutex_unlock(&decodemutex);
- av_free_packet(&pkt);
+ av_packet_unref(&pkt);
}
bool DJICameraStreamDecoder::registerCallback(CameraImageCallback f, void *param)
|