aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-10-03 17:57:51 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-10-03 17:57:51 +0200
commitd5dcc19a006f898f21a5b081180a132c9dc6e638 (patch)
treef0e155c31bf098133e7ceafa2fa6272608589304
parentbb65f0fc2176b2ebf0f1be682008609e8bd2cb0a (diff)
downloadosc-graphics-d5dcc19a006f898f21a5b081180a132c9dc6e638.tar.gz
use ffmpeg API to set a recorded frames presentation timestamp
* fixes asynchronity of displayed and recorded graphics * also use the configured framerate instead of a hardcoded one
-rw-r--r--configure.ac2
-rw-r--r--src/main.cpp6
-rw-r--r--src/osc_graphics.h4
-rw-r--r--src/recorder.cpp21
-rw-r--r--src/recorder.h1
5 files changed, 27 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index fbd57a5..4af841d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,7 +81,7 @@ AC_CHECK_HEADERS([SDL_ttf.h], , [
AC_CHECK_LIB(SDL_ffmpeg, SDL_ffmpegOpen, , [
AC_MSG_ERROR([Required libSDL_ffmpeg missing!])
])
-AC_CHECK_HEADERS([SDL/SDL_ffmpeg.h], , [
+AC_CHECK_HEADERS([SDL/SDL_ffmpeg.h libavcodec/avcodec.h], , [
AC_MSG_ERROR([Required libSDL_ffmpeg header missing!])
])
diff --git a/src/main.cpp b/src/main.cpp
index 8fd714f..d353a52 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -56,6 +56,7 @@ static Recorder recorder;
LayerList layers;
int config_dump_osc = 0;
+int config_framerate = DEFAULT_FRAMERATE;
void
rgba_blit_with_alpha(SDL_Surface *src_surf, SDL_Surface *dst_surf, Uint8 alpha)
@@ -240,11 +241,10 @@ main(int argc, char **argv)
int width = DEFAULT_SCREEN_WIDTH;
int height = DEFAULT_SCREEN_HEIGHT;
int bpp = DEFAULT_SCREEN_BPP;
- int framerate = DEFAULT_FRAMERATE;
parse_options(argc, argv,
port, sdl_flags, show_cursor,
- width, height, bpp, framerate);
+ width, height, bpp, config_framerate);
if (SDL_Init(SDL_INIT_VIDEO)) {
SDL_ERROR("SDL_Init");
@@ -279,7 +279,7 @@ main(int argc, char **argv)
osc_server.start();
SDL_initFramerate(&fpsm);
- SDL_setFramerate(&fpsm, framerate);
+ SDL_setFramerate(&fpsm, config_framerate);
for (;;) {
sdl_process_events();
diff --git a/src/osc_graphics.h b/src/osc_graphics.h
index 47afa7d..9ae1ee4 100644
--- a/src/osc_graphics.h
+++ b/src/osc_graphics.h
@@ -65,6 +65,10 @@ public:
extern SDL_Surface *screen;
extern int config_dump_osc;
+extern int config_framerate;
+
+#define FRAME_DELAY \
+ (1000/config_framerate) /* frame delay in ms */
void rgba_blit_with_alpha(SDL_Surface *src_surf, SDL_Surface *dst_surf,
Uint8 alpha = SDL_ALPHA_TRANSPARENT);
diff --git a/src/recorder.cpp b/src/recorder.cpp
index 0bd7b23..9680079 100644
--- a/src/recorder.cpp
+++ b/src/recorder.cpp
@@ -2,12 +2,18 @@
#include "config.h"
#endif
+#define __STDC_CONSTANT_MACROS
#include <stdlib.h>
#include <stdio.h>
+#include <stdint.h>
#include <SDL.h>
#include <SDL/SDL_ffmpeg.h>
+extern "C" {
+#include <libavcodec/avcodec.h>
+}
+
#include "osc_graphics.h"
#include "osc_server.h"
@@ -64,7 +70,7 @@ Recorder::start(const char *filename)
SDL_ffmpegCodec codec = {
-1, /* video codec based on file name */
screen->w, screen->h,
- 1, 20 /* FIXME */, /* framerate */
+ 1, config_framerate, /* framerate */
6000000, -1, -1,
-1, 0, -1, -1, -1, -1 /* no audio */
};
@@ -87,6 +93,8 @@ Recorder::start(const char *filename)
SDL_ffmpegAddVideoStream(file, codec);
SDL_ffmpegSelectVideoStream(file, 0);
+ start_time = SDL_GetTicks();
+
unlock();
}
@@ -114,8 +122,15 @@ Recorder::record(SDL_Surface *surf)
{
lock();
- if (file)
- SDL_ffmpegAddVideoFrame(file, surf);
+ if (file) {
+ struct AVFrame *frame = file->videoStream->encodeFrame;
+ int64_t pts = (SDL_GetTicks() - start_time)/FRAME_DELAY;
+
+ if (pts > frame->pts) {
+ frame->pts = pts;
+ SDL_ffmpegAddVideoFrame(file, surf);
+ }
+ }
unlock();
}
diff --git a/src/recorder.h b/src/recorder.h
index 591312e..62458ad 100644
--- a/src/recorder.h
+++ b/src/recorder.h
@@ -8,6 +8,7 @@
class Recorder : Mutex {
SDL_ffmpegFile *file;
+ Uint32 start_time;
public:
Recorder() : Mutex(), file(NULL) {}