summaryrefslogtreecommitdiff
path: root/ffmpeg_backend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ffmpeg_backend.cpp')
-rw-r--r--ffmpeg_backend.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/ffmpeg_backend.cpp b/ffmpeg_backend.cpp
index 89c0c91..34abf35 100644
--- a/ffmpeg_backend.cpp
+++ b/ffmpeg_backend.cpp
@@ -112,7 +112,7 @@ void AV_Dealloc(av_info *AV)
av_frame_free(&AV->VideoFrame);
};
-void AV_Init(source *Source, av_info *AV, memory *Memory)
+void AV_Init(block_source *Source, av_info *AV, memory *Memory)
{
*AV = {};
@@ -197,21 +197,21 @@ void AV_Init(source *Source, av_info *AV, memory *Memory)
fprintf(stderr, "Libav error: (%s)\n", av_err2str(err));
}
- Source->Info.BytesPerPixel = 4;
- Source->Info.FPS = (real32)AV->VideoStream->r_frame_rate.num / AV->VideoStream->r_frame_rate.den;
- Source->Info.Width = AV->VideoCodecContext->width;
- Source->Info.Height = AV->VideoCodecContext->height;
+ Source->BytesPerPixel = 4;
+ Source->FPS = (real32)AV->VideoStream->r_frame_rate.num / AV->VideoStream->r_frame_rate.den;
+ Source->Width = AV->VideoCodecContext->width;
+ Source->Height = AV->VideoCodecContext->height;
};
-void AV_GetPTSAverage(source *Source, av_info *AV, int32 *err)
+void AV_GetPTSAverage(block_source *Source, av_info *AV, int32 *err)
{
// TODO(fox): This PTS average isn't exact and causes an occasional
// frame skip. See libav remarks in forum for more details.
if (AV->VideoStream->duration == 1) {
- Source->Info.AvgPTSPerFrame = 1;
+ Source->AvgPTSPerFrame = 1;
return;
}
@@ -234,13 +234,14 @@ void AV_GetPTSAverage(source *Source, av_info *AV, int32 *err)
}
}
- Source->Info.AvgPTSPerFrame = (real32)AvgPTSPerSecond / (int32)(FPS + 0.5f);
- printf("Avg PTS per sec: %.06f, Avg PTS per frame: %.06f\n", AvgPTSPerSecond, Source->Info.AvgPTSPerFrame);
+ Source->AvgPTSPerFrame = (real32)AvgPTSPerSecond / (int32)(FPS + 0.5f);
+ printf("Avg PTS per sec: %.06f, Avg PTS per frame: %.06f\n", AvgPTSPerSecond, Source->AvgPTSPerFrame);
av_seek_frame(AV->FileFormatContext, -1, 0, AVSEEK_FLAG_BACKWARD);
}
-cached_bitmap * AV_LoadStill(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory)
+#if 0
+cached_bitmap * AV_LoadStill(block_source *Source, layer_bitmap_info *BitmapInfo, memory *Memory)
{
av_info *AV = (av_info *)BitmapInfo->AVInfo;
int32 *CurrentlyRenderedFrame = &BitmapInfo->CurrentFrame;
@@ -254,9 +255,9 @@ cached_bitmap * AV_LoadStill(source *Source, layer_bitmap_info *BitmapInfo, memo
while (err >= 0) {
if (AV_TryFrame(AV, &err))
{
- uint16 Width = Source->Info.Width;
- uint16 Height = Source->Info.Height;
- uint16 BytesPerPixel = Source->Info.BytesPerPixel;
+ uint16 Width = Source->Width;
+ uint16 Height = Source->Height;
+ uint16 BytesPerPixel = Source->BytesPerPixel;
int32 Pitch = Width*BytesPerPixel;
cached_bitmap *Bitmap = Memory_RollingBitmap(Memory, Source, 0);
@@ -295,10 +296,10 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo,
int32 err = 0;
- if (!Source->Info.AvgPTSPerFrame) {
+ if (!Source->AvgPTSPerFrame) {
AV_GetPTSAverage(Source, AV, &err);
}
- Assert(Source->Info.AvgPTSPerFrame);
+ Assert(Source->AvgPTSPerFrame);
int32 FrameToSeek = TimelineFrame - BitmapInfo->FrameOffset;
if (*CurrentlyRenderedFrame == FrameToSeek || FrameToSeek < 0)
@@ -309,7 +310,7 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo,
// This function only seeks to the nearest "keyframe."
if (*CurrentlyRenderedFrame != FrameToSeek - 1) {
- int64 SeekSeconds = (int64)(FrameToSeek / (int32)(Source->Info.FPS + 0.5f) * AV_TIME_BASE);
+ int64 SeekSeconds = (int64)(FrameToSeek / (int32)(Source->FPS + 0.5f) * AV_TIME_BASE);
av_seek_frame(AV->FileFormatContext, -1, SeekSeconds, AVSEEK_FLAG_BACKWARD);
printf("Seek activated\n");
} else if (*CurrentlyRenderedFrame < 0) {
@@ -318,7 +319,7 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo,
*CurrentlyRenderedFrame = FrameToSeek;
- int64 SeekPTS = (int64)(Source->Info.AvgPTSPerFrame*FrameToSeek + 0.5f);
+ int64 SeekPTS = (int64)(Source->AvgPTSPerFrame*FrameToSeek + 0.5f);
while (err >= 0) {
if (AV_TryFrame(AV, &err)) {
@@ -332,7 +333,7 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo,
}
int64 Difference = AV->VideoFrame->pts - SeekPTS;
- if (abs(Difference) < Source->Info.AvgPTSPerFrame)
+ if (abs(Difference) < Source->AvgPTSPerFrame)
{
if (AV->PreviousPTS == -1) {
AV->PreviousPTS = AV->VideoFrame->pts;
@@ -342,9 +343,9 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo,
AV->PreviousPTS = AV->VideoFrame->pts;
}
- uint16 Width = Source->Info.Width;
- uint16 Height = Source->Info.Height;
- uint16 BytesPerPixel = Source->Info.BytesPerPixel;
+ uint16 Width = Source->Width;
+ uint16 Height = Source->Height;
+ uint16 BytesPerPixel = Source->BytesPerPixel;
int32 Pitch = Width*BytesPerPixel;
cached_bitmap *Bitmap = Memory_RollingBitmap(Memory, Source, FrameToSeek);
@@ -381,3 +382,4 @@ cached_bitmap * AV_LoadVideoFrame(source *Source, layer_bitmap_info *BitmapInfo,
}
return 0;
}
+#endif