@@ -15,6 +15,59 @@ extern "C" {
1515#include < libavutil/pixdesc.h>
1616#include < libavcodec/mediacodec.h>
1717#include < libavutil/hwcontext_mediacodec.h>
18+ #include < stdatomic.h>
19+
20+ struct FFAMediaCodec ;
21+ struct FFAMediaFormat ;
22+ // libavcodec/mediacodecdec_common.h
23+ typedef struct MediaCodecDecContext {
24+
25+ AVCodecContext *avctx;
26+ atomic_int refcount;
27+ atomic_int hw_buffer_count;
28+
29+ char *codec_name;
30+
31+ FFAMediaCodec *codec;
32+ FFAMediaFormat *format;
33+
34+ void *surface;
35+
36+ int started;
37+ int draining;
38+ int flushing;
39+ int eos;
40+
41+ int width;
42+ int height;
43+ int stride;
44+ int slice_height;
45+ int color_format;
46+ int crop_top;
47+ int crop_bottom;
48+ int crop_left;
49+ int crop_right;
50+ int display_width;
51+ int display_height;
52+
53+ uint64_t output_buffer_count;
54+ ssize_t current_input_buffer;
55+
56+ bool delay_flush;
57+ atomic_int serial;
58+
59+ bool use_ndk_codec;
60+ } MediaCodecDecContext;
61+
62+ typedef struct MediaCodecBuffer {
63+
64+ MediaCodecDecContext *ctx;
65+ ssize_t index;
66+ int64_t pts;
67+ atomic_int released;
68+ int serial;
69+
70+ } MediaCodecBuffer;
1871}
1972
2073QT_BEGIN_NAMESPACE
@@ -96,7 +149,7 @@ class VideoBuffer_MediaCodec : public QAVVideoBuffer_GPU
96149 m_hw->androidSurfaceTexture ->attachToGLContext (m_hw->texture );
97150 }
98151
99- AVMediaCodecBuffer * buffer = reinterpret_cast <AVMediaCodecBuffer *>(frame ().frame ()->data [3 ]);
152+ auto buffer = reinterpret_cast <AVMediaCodecBuffer *>(frame ().frame ()->data [3 ]);
100153 if (!buffer) {
101154 qWarning () << " Received a frame without AVMediaCodecBuffer." ;
102155 } else if (av_mediacodec_release_buffer (buffer, 1 ) < 0 ) {
@@ -108,6 +161,17 @@ class VideoBuffer_MediaCodec : public QAVVideoBuffer_GPU
108161 return m_hw->texture ;
109162 }
110163
164+ QSize size () const override
165+ {
166+ auto av_frame = frame ().frame ();
167+ auto buffer = reinterpret_cast <AVMediaCodecBuffer *>(av_frame->data [3 ]);
168+ if (!buffer) {
169+ return frame ().size ();
170+ }
171+ auto ctx = reinterpret_cast <MediaCodecDecContext *>(buffer->ctx );
172+ return {ctx->width , ctx->height };
173+ }
174+
111175 QAVHWDevice_MediaCodecPrivate *m_hw = nullptr ;
112176};
113177
0 commit comments