@@ -47,7 +47,7 @@ static LCEVC_ColorFormat map_format(int format)
47
47
return LCEVC_ColorFormat_Unknown ;
48
48
}
49
49
50
- static int alloc_base_frame (void * logctx , LCEVC_DecoderHandle decoder ,
50
+ static int alloc_base_frame (void * logctx , FFLCEVCContext * lcevc ,
51
51
const AVFrame * frame , LCEVC_PictureHandle * picture )
52
52
{
53
53
LCEVC_PictureDesc desc ;
@@ -70,22 +70,22 @@ static int alloc_base_frame(void *logctx, LCEVC_DecoderHandle decoder,
70
70
desc .sampleAspectRatioDen = frame -> sample_aspect_ratio .den ;
71
71
72
72
/* Allocate LCEVC Picture */
73
- res = LCEVC_AllocPicture (decoder , & desc , picture );
73
+ res = LCEVC_AllocPicture (lcevc -> decoder , & desc , picture );
74
74
if (res != LCEVC_Success ) {
75
75
return AVERROR_EXTERNAL ;
76
76
}
77
- res = LCEVC_LockPicture (decoder , * picture , LCEVC_Access_Write , & lock );
77
+ res = LCEVC_LockPicture (lcevc -> decoder , * picture , LCEVC_Access_Write , & lock );
78
78
if (res != LCEVC_Success )
79
79
return AVERROR_EXTERNAL ;
80
80
81
- res = LCEVC_GetPicturePlaneCount (decoder , * picture , & planes );
81
+ res = LCEVC_GetPicturePlaneCount (lcevc -> decoder , * picture , & planes );
82
82
if (res != LCEVC_Success )
83
83
return AVERROR_EXTERNAL ;
84
84
85
85
for (unsigned i = 0 ; i < planes ; i ++ ) {
86
86
LCEVC_PicturePlaneDesc plane ;
87
87
88
- res = LCEVC_GetPictureLockPlaneDesc (decoder , lock , i , & plane );
88
+ res = LCEVC_GetPictureLockPlaneDesc (lcevc -> decoder , lock , i , & plane );
89
89
if (res != LCEVC_Success )
90
90
return AVERROR_EXTERNAL ;
91
91
@@ -96,43 +96,43 @@ static int alloc_base_frame(void *logctx, LCEVC_DecoderHandle decoder,
96
96
av_image_copy2 (data , linesizes , frame -> data , frame -> linesize ,
97
97
frame -> format , frame -> width , frame -> height );
98
98
99
- res = LCEVC_UnlockPicture (decoder , lock );
99
+ res = LCEVC_UnlockPicture (lcevc -> decoder , lock );
100
100
if (res != LCEVC_Success )
101
101
return AVERROR_EXTERNAL ;
102
102
103
103
return 0 ;
104
104
}
105
105
106
- static int alloc_enhanced_frame (void * logctx , LCEVC_DecoderHandle decoder ,
107
- const AVFrame * frame , LCEVC_PictureHandle * picture )
106
+ static int alloc_enhanced_frame (void * logctx , FFLCEVCFrame * frame_ctx ,
107
+ LCEVC_PictureHandle * picture )
108
108
{
109
+ FFLCEVCContext * lcevc = frame_ctx -> lcevc ;
109
110
LCEVC_PictureDesc desc ;
110
- LCEVC_ColorFormat fmt = map_format (frame -> format );
111
+ LCEVC_ColorFormat fmt = map_format (frame_ctx -> frame -> format );
111
112
LCEVC_PicturePlaneDesc planes [4 ] = { 0 };
112
- int width = frame -> width * 2 / FFMAX (frame -> sample_aspect_ratio .den , 1 );
113
- int height = frame -> height * 2 / FFMAX (frame -> sample_aspect_ratio .num , 1 );
114
113
LCEVC_ReturnCode res ;
115
114
116
- res = LCEVC_DefaultPictureDesc (& desc , fmt , width , height );
115
+ res = LCEVC_DefaultPictureDesc (& desc , fmt , frame_ctx -> frame -> width , frame_ctx -> frame -> height );
117
116
if (res != LCEVC_Success )
118
117
return AVERROR_EXTERNAL ;
119
118
120
119
/* Set plane description */
121
120
for (int i = 0 ; i < 4 ; i ++ ) {
122
- planes [i ].firstSample = frame -> data [i ];
123
- planes [i ].rowByteStride = frame -> linesize [i ];
121
+ planes [i ].firstSample = frame_ctx -> frame -> data [i ];
122
+ planes [i ].rowByteStride = frame_ctx -> frame -> linesize [i ];
124
123
}
125
124
126
125
/* Allocate LCEVC Picture */
127
- res = LCEVC_AllocPictureExternal (decoder , & desc , NULL , planes , picture );
126
+ res = LCEVC_AllocPictureExternal (lcevc -> decoder , & desc , NULL , planes , picture );
128
127
if (res != LCEVC_Success ) {
129
128
return AVERROR_EXTERNAL ;
130
129
}
131
130
return 0 ;
132
131
}
133
132
134
- static int lcevc_send_frame (void * logctx , FFLCEVCContext * lcevc , const AVFrame * in )
133
+ static int lcevc_send_frame (void * logctx , FFLCEVCFrame * frame_ctx , const AVFrame * in )
135
134
{
135
+ FFLCEVCContext * lcevc = frame_ctx -> lcevc ;
136
136
const AVFrameSideData * sd = av_frame_get_side_data (in , AV_FRAME_DATA_LCEVC );
137
137
LCEVC_PictureHandle picture ;
138
138
LCEVC_ReturnCode res ;
@@ -145,7 +145,7 @@ static int lcevc_send_frame(void *logctx, FFLCEVCContext *lcevc, const AVFrame *
145
145
if (res != LCEVC_Success )
146
146
return AVERROR_EXTERNAL ;
147
147
148
- ret = alloc_base_frame (logctx , lcevc -> decoder , in , & picture );
148
+ ret = alloc_base_frame (logctx , lcevc , in , & picture );
149
149
if (ret < 0 )
150
150
return ret ;
151
151
@@ -154,7 +154,7 @@ static int lcevc_send_frame(void *logctx, FFLCEVCContext *lcevc, const AVFrame *
154
154
return AVERROR_EXTERNAL ;
155
155
156
156
memset (& picture , 0 , sizeof (picture ));
157
- ret = alloc_enhanced_frame (logctx , lcevc -> decoder , in , & picture );
157
+ ret = alloc_enhanced_frame (logctx , frame_ctx , & picture );
158
158
if (ret < 0 )
159
159
return ret ;
160
160
@@ -165,8 +165,9 @@ static int lcevc_send_frame(void *logctx, FFLCEVCContext *lcevc, const AVFrame *
165
165
return 0 ;
166
166
}
167
167
168
- static int generate_output (void * logctx , FFLCEVCContext * lcevc , AVFrame * out )
168
+ static int generate_output (void * logctx , FFLCEVCFrame * frame_ctx , AVFrame * out )
169
169
{
170
+ FFLCEVCContext * lcevc = frame_ctx -> lcevc ;
170
171
LCEVC_PictureDesc desc ;
171
172
LCEVC_DecodeInformation info ;
172
173
LCEVC_PictureHandle picture ;
@@ -186,6 +187,11 @@ static int generate_output(void *logctx, FFLCEVCContext *lcevc, AVFrame *out)
186
187
out -> crop_right = desc .cropRight ;
187
188
out -> sample_aspect_ratio .num = desc .sampleAspectRatioNum ;
188
189
out -> sample_aspect_ratio .den = desc .sampleAspectRatioDen ;
190
+
191
+ av_frame_copy_props (frame_ctx -> frame , out );
192
+ av_frame_unref (out );
193
+ av_frame_move_ref (out , frame_ctx -> frame );
194
+
189
195
out -> width = desc .width + out -> crop_left + out -> crop_right ;
190
196
out -> height = desc .height + out -> crop_top + out -> crop_bottom ;
191
197
@@ -196,13 +202,14 @@ static int generate_output(void *logctx, FFLCEVCContext *lcevc, AVFrame *out)
196
202
return 0 ;
197
203
}
198
204
199
- static int lcevc_receive_frame (void * logctx , FFLCEVCContext * lcevc , AVFrame * out )
205
+ static int lcevc_receive_frame (void * logctx , FFLCEVCFrame * frame_ctx , AVFrame * out )
200
206
{
207
+ FFLCEVCContext * lcevc = frame_ctx -> lcevc ;
201
208
LCEVC_PictureHandle picture ;
202
209
LCEVC_ReturnCode res ;
203
210
int ret ;
204
211
205
- ret = generate_output (logctx , lcevc , out );
212
+ ret = generate_output (logctx , frame_ctx , out );
206
213
if (ret < 0 )
207
214
return ret ;
208
215
@@ -249,12 +256,7 @@ static int lcevc_init(FFLCEVCContext *lcevc, void *logctx)
249
256
#if CONFIG_LIBLCEVC_DEC
250
257
LCEVC_AccelContextHandle dummy = { 0 };
251
258
const int32_t event = LCEVC_Log ;
252
- #endif
253
259
254
- if (lcevc -> initialized )
255
- return 0 ;
256
-
257
- #if CONFIG_LIBLCEVC_DEC
258
260
if (LCEVC_CreateDecoder (& lcevc -> decoder , dummy ) != LCEVC_Success ) {
259
261
av_log (logctx , AV_LOG_ERROR , "Failed to create LCEVC decoder\n" );
260
262
return AVERROR_EXTERNAL ;
@@ -279,7 +281,8 @@ static int lcevc_init(FFLCEVCContext *lcevc, void *logctx)
279
281
int ff_lcevc_process (void * logctx , AVFrame * frame )
280
282
{
281
283
FrameDecodeData * fdd = frame -> private_ref ;
282
- FFLCEVCContext * lcevc = fdd -> post_process_opaque ;
284
+ FFLCEVCFrame * frame_ctx = fdd -> post_process_opaque ;
285
+ FFLCEVCContext * lcevc = frame_ctx -> lcevc ;
283
286
int ret ;
284
287
285
288
if (!lcevc -> initialized ) {
@@ -289,11 +292,14 @@ int ff_lcevc_process(void *logctx, AVFrame *frame)
289
292
}
290
293
291
294
#if CONFIG_LIBLCEVC_DEC
292
- ret = lcevc_send_frame (logctx , lcevc , frame );
295
+ av_assert0 (frame_ctx -> frame );
296
+
297
+
298
+ ret = lcevc_send_frame (logctx , frame_ctx , frame );
293
299
if (ret )
294
300
return ret < 0 ? ret : 0 ;
295
301
296
- lcevc_receive_frame (logctx , lcevc , frame );
302
+ lcevc_receive_frame (logctx , frame_ctx , frame );
297
303
if (ret < 0 )
298
304
return ret ;
299
305
@@ -317,5 +323,8 @@ int ff_lcevc_alloc(FFLCEVCContext **plcevc)
317
323
318
324
void ff_lcevc_unref (void * opaque )
319
325
{
320
- av_refstruct_unref (& opaque );
326
+ FFLCEVCFrame * lcevc = opaque ;
327
+ av_refstruct_unref (& lcevc -> lcevc );
328
+ av_frame_free (& lcevc -> frame );
329
+ av_free (opaque );
321
330
}
0 commit comments