Skip to content

Commit 36c87d4

Browse files
committed
Fixes the width/height to the hw frames with the coded_width/height
1 parent a8409f5 commit 36c87d4

2 files changed

Lines changed: 9 additions & 21 deletions

File tree

FlyleafLib/MediaFramework/MediaDecoder/VideoDecoder.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,7 @@ public VideoDecoder(Config config, Control control = null, int uniqueId = -1, bo
187187
AVBufferRef* hwframes;
188188
private unsafe AVPixelFormat get_format(AVCodecContext* avctx, AVPixelFormat* pix_fmts)
189189
{
190-
Log("get_format");
191-
192-
//if (codecCtx->hw_frames_ctx == null)
193-
// return AVPixelFormat.AV_PIX_FMT_NONE;
194-
195-
if (AllocateHWFrames() != 0)
196-
Log("Hmmm...");
190+
AllocateHWFrames();
197191

198192
return AVPixelFormat.AV_PIX_FMT_D3D11;
199193
}
@@ -205,10 +199,10 @@ private bool ShouldAllocateNew()
205199

206200
var t2 = (AVHWFramesContext*) hwframes->data;
207201

208-
if (codecCtx->width != t2->width)
202+
if (codecCtx->coded_width != t2->width)
209203
return true;
210204

211-
if (codecCtx->height != t2->height)
205+
if (codecCtx->coded_height != t2->height)
212206
return true;
213207

214208
var fmt = codecCtx->sw_pix_fmt == AVPixelFormat.AV_PIX_FMT_YUV420P10LE ? AVPixelFormat.AV_PIX_FMT_P010LE : AVPixelFormat.AV_PIX_FMT_NV12;
@@ -222,19 +216,13 @@ private int AllocateHWFrames()
222216
if (!ShouldAllocateNew())
223217
{
224218
if (hwframes != null && codecCtx->hw_frames_ctx == null)
225-
{
226219
codecCtx->hw_frames_ctx = av_buffer_ref(hwframes);
227-
Log("Already allocated 1");
228-
}
229-
else
230-
Log("Already allocated 2");
231220

232221
textDesc.Format = textureFFmpeg.Description.Format;
222+
233223
return 0;
234224
}
235225

236-
Log("Allocating ...");
237-
238226
if (hwframes != null)
239227
fixed(AVBufferRef** ptr = &hwframes) av_buffer_unref(ptr);
240228

@@ -248,8 +236,8 @@ private int AllocateHWFrames()
248236
var t2 = (AVHWFramesContext*)(codecCtx->hw_frames_ctx->data);
249237
t2->format = AVPixelFormat.AV_PIX_FMT_D3D11;
250238
t2->sw_format = codecCtx->sw_pix_fmt == AVPixelFormat.AV_PIX_FMT_YUV420P10LE ? AVPixelFormat.AV_PIX_FMT_P010LE : AVPixelFormat.AV_PIX_FMT_NV12;
251-
t2->width = codecCtx->width;
252-
t2->height = codecCtx->height;
239+
t2->width = codecCtx->coded_width;
240+
t2->height = codecCtx->coded_height;
253241
t2->initial_pool_size = 20;
254242

255243
AVD3D11VAFramesContext *t3 = (AVD3D11VAFramesContext *)t2->hwctx;
@@ -261,8 +249,8 @@ private int AllocateHWFrames()
261249
int ret = av_hwframe_ctx_init(codecCtx->hw_frames_ctx);
262250
if (ret == 0)
263251
{
264-
textureFFmpeg = new ID3D11Texture2D((IntPtr) t3->texture);
265-
textDesc.Format = textureFFmpeg.Description.Format;
252+
textureFFmpeg = new ID3D11Texture2D((IntPtr) t3->texture);
253+
textDesc.Format = textureFFmpeg.Description.Format;
266254
}
267255

268256
return ret;

Samples/FlyleafPlayer (WPF Control) (WPF)/FlyleafPlayer (WPF Control) (WPF).csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</ItemGroup>
3030

3131
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
32-
<Exec Command="xcopy &quot;$(SolutionDir)Plugins.NET5\&quot; &quot;$(TargetDir)Plugins\&quot; /E /Y&#xD;&#xA;&#xD;&#xA;if not exist &quot;$(TargetDir)Libs&quot; mkdir &quot;$(TargetDir)Libs&quot;&#xD;&#xA;&#xD;&#xA;if $(PlatformName) == x86 (&#xD;&#xA; xcopy &quot;$(SolutionDir)Libs\x86\*&quot; &quot;$(TargetDir)Libs\x86\&quot; /E /Y&#xD;&#xA;)&#xD;&#xA;if $(PlatformName) == x64 (&#xD;&#xA; xcopy &quot;$(SolutionDir)Libs\x64\*&quot; &quot;$(TargetDir)Libs\x64\&quot; /E /Y&#xD;&#xA;)" />
32+
<Exec Command="xcopy &quot;$(SolutionDir)Plugins.NET6\&quot; &quot;$(TargetDir)Plugins\&quot; /E /Y&#xD;&#xA;&#xD;&#xA;if not exist &quot;$(TargetDir)Libs&quot; mkdir &quot;$(TargetDir)Libs&quot;&#xD;&#xA;&#xD;&#xA;if $(PlatformName) == x86 (&#xD;&#xA; xcopy &quot;$(SolutionDir)Libs\x86\*&quot; &quot;$(TargetDir)Libs\x86\&quot; /E /Y&#xD;&#xA;)&#xD;&#xA;if $(PlatformName) == x64 (&#xD;&#xA; xcopy &quot;$(SolutionDir)Libs\x64\*&quot; &quot;$(TargetDir)Libs\x64\&quot; /E /Y&#xD;&#xA;)" />
3333
</Target>
3434

3535
<Target Name="PostPublish" AfterTargets="Publish">

0 commit comments

Comments
 (0)