summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2013-01-29 16:10:55 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2013-01-29 16:34:07 +0100
commit181663291357bfad4d1e630f3c5932847a2a0520 (patch)
treeef47e9b364e163341216a0c837069b8be8e27db5
parent87e95e6868580df0ba9e1ba97b3f1d4dd66f7b9c (diff)
downloadadvtime-181663291357bfad4d1e630f3c5932847a2a0520.tar.gz
advtime-181663291357bfad4d1e630f3c5932847a2a0520.tar.bz2
advtime-181663291357bfad4d1e630f3c5932847a2a0520.zip
video-decode: Allow reusing an old frame
-rw-r--r--src/advtime.c17
-rw-r--r--src/frame_to_pgm.c2
-rw-r--r--src/video_decode.c16
3 files changed, 24 insertions, 11 deletions
diff --git a/src/advtime.c b/src/advtime.c
index 89af714..93a4057 100644
--- a/src/advtime.c
+++ b/src/advtime.c
@@ -9,6 +9,16 @@
#include "video_decode.h"
#include "util.h"
+static inline void
+pswap(void **p1, void **p2)
+{
+ void *tmp;
+
+ tmp = *p1;
+ *p1 = *p2;
+ *p2 = tmp;
+}
+
/* print time in format: "hh:mm:ss.xxx" */
static void
print_time(int64_t msec) {
@@ -75,8 +85,7 @@ int
main(int argc, char **argv)
{
struct video_decode *vd;
- struct video_frame *frame_a;
- struct video_frame *frame_b;
+ struct video_frame *frame_a = NULL, *frame_b = NULL, *tmp;
int ret, ch;
int diff_flag = 0, average_flag = 0, frame_flag = 0, showcut_flag = 0;
int64_t timestamp = 0;
@@ -177,10 +186,10 @@ main(int argc, char **argv)
if (frame_flag || average_flag)
printf("\n");
- video_decode_free_frame(&frame_a);
- frame_a = frame_b;
+ pswap(&frame_a, &frame_b);
}
+ video_decode_free_frame(&frame_a);
video_decode_free_frame(&frame_b);
video_decode_uninit(&vd);
return EXIT_SUCCESS;
diff --git a/src/frame_to_pgm.c b/src/frame_to_pgm.c
index 36e9ac8..b878968 100644
--- a/src/frame_to_pgm.c
+++ b/src/frame_to_pgm.c
@@ -21,7 +21,7 @@ int
main(int argc, char **argv)
{
struct video_decode *vd;
- struct video_frame *frame;
+ struct video_frame *frame = NULL;
int ret;
int64_t timestamp = 0;
diff --git a/src/video_decode.c b/src/video_decode.c
index 993fd14..e6748e0 100644
--- a/src/video_decode.c
+++ b/src/video_decode.c
@@ -97,9 +97,14 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame)
int decoded, got_picture;
int ret;
- f = calloc(1, sizeof *f);
- if (f == NULL)
- return -1;
+ if (*frame != NULL) {
+ f = *frame;
+ } else {
+ f = calloc(1, sizeof *f);
+ if (f == NULL)
+ return -1;
+ f->frame = avcodec_alloc_frame();
+ }
packet.data = NULL;
do {
@@ -122,8 +127,6 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame)
}
} while (packet.stream_index != vd->stream);
- f->frame = avcodec_alloc_frame();
-
do {
#if DEBUG
printf("packet.data: %p, packet.siz: %d, packet.strm_idx: %d\n",
@@ -150,7 +153,8 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame)
f->base.height = vd->codec_ctx->height;
f->base.stride = f->frame->linesize[0];
- *frame = &f->base;
+ if (*frame == NULL)
+ *frame = &f->base;
return 1;
}