#include <math.h>
#include <limits.h>
#include "libavutil/avstring.h"
+#include "libavutil/pixdesc.h"
#include "libavformat/avformat.h"
#include "libavdevice/avdevice.h"
#include "libswscale/swscale.h"
//#define DEBUG_SYNC
-#define MAX_VIDEOQ_SIZE (5 * 256 * 1024)
-#define MAX_AUDIOQ_SIZE (20 * 16 * 1024)
-#define MAX_SUBTITLEQ_SIZE (5 * 16 * 1024)
+#define MAX_QUEUE_SIZE (15 * 1024 * 1024)
+#define MIN_AUDIOQ_SIZE (20 * 16 * 1024)
+#define MIN_FRAMES 5
/* SDL audio buffer size, in samples. Should be small to have precise
A/V sync as SDL does not have hardware buffer fullness info. */
int audio_hw_buf_size;
/* samples output by the codec. we reserve more space for avsync
compensation */
- DECLARE_ALIGNED(16,uint8_t,audio_buf1[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]);
- DECLARE_ALIGNED(16,uint8_t,audio_buf2[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]);
+ DECLARE_ALIGNED(16,uint8_t,audio_buf1)[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
+ DECLARE_ALIGNED(16,uint8_t,audio_buf2)[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2];
uint8_t *audio_buf;
unsigned int audio_buf_size; /* in bytes */
int audio_buf_index; /* in bytes */
}
/* seek in the stream */
-static void stream_seek(VideoState *is, int64_t pos, int64_t rel)
+static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_bytes)
{
if (!is->seek_req) {
is->seek_pos = pos;
enc->skip_loop_filter= skip_loop_filter;
enc->error_recognition= error_recognition;
enc->error_concealment= error_concealment;
+ avcodec_thread_init(enc, thread_count);
set_context_opts(enc, avcodec_opts[enc->codec_type], 0);
is->audio_src_fmt= SAMPLE_FMT_S16;
}
- if(thread_count>1)
- avcodec_thread_init(enc, thread_count);
- enc->thread_count= thread_count;
ic->streams[stream_index]->discard = AVDISCARD_DEFAULT;
switch(enc->codec_type) {
case CODEC_TYPE_AUDIO:
AVFormatParameters params, *ap = ¶ms;
int eof=0;
+ ic = avformat_alloc_context();
+
video_index = -1;
audio_index = -1;
subtitle_index = -1;
memset(ap, 0, sizeof(*ap));
+ ap->prealloced_context = 1;
ap->width = frame_width;
ap->height= frame_height;
ap->time_base= (AVRational){1, 25};
ap->pix_fmt = frame_pix_fmt;
+ set_context_opts(ic, avformat_opts, AV_OPT_FLAG_DECODING_PARAM);
+
err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);
if (err < 0) {
print_error(is->filename, err);
}
/* if the queue are full, no need to read more */
- if (is->audioq.size > MAX_AUDIOQ_SIZE ||
- is->videoq.size > MAX_VIDEOQ_SIZE ||
- is->subtitleq.size > MAX_SUBTITLEQ_SIZE) {
+ if ( is->audioq.size + is->videoq.size + is->subtitleq.size > MAX_QUEUE_SIZE
+ || ( (is->audioq .size > MIN_AUDIOQ_SIZE || is->audio_stream<0)
+ && (is->videoq .nb_packets > MIN_FRAMES || is->video_stream<0)
+ && (is->subtitleq.nb_packets > MIN_FRAMES || is->subtitle_stream<0))) {
/* wait 10 ms */
SDL_Delay(10);
continue;
else
incr *= 180000.0;
pos += incr;
- stream_seek(cur_stream, pos, incr);
+ stream_seek(cur_stream, pos, incr, 1);
} else {
pos = get_master_clock(cur_stream);
pos += incr;
- stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE));
+ stream_seek(cur_stream, (int64_t)(pos * AV_TIME_BASE), (int64_t)(incr * AV_TIME_BASE), 0);
}
}
break;
break;
case SDL_MOUSEBUTTONDOWN:
if (cur_stream) {
+ if(seek_by_bytes || cur_stream->ic->duration<=0){
+ uint64_t size= url_fsize(cur_stream->ic->pb);
+ stream_seek(cur_stream, size*(double)event.button.x/(double)cur_stream->width, 0, 1);
+ }else{
int64_t ts;
int ns, hh, mm, ss;
int tns, thh, tmm, tss;
ts = frac*cur_stream->ic->duration;
if (cur_stream->ic->start_time != AV_NOPTS_VALUE)
ts += cur_stream->ic->start_time;
- stream_seek(cur_stream, ts, 0);
+ stream_seek(cur_stream, ts, 0, 0);
+ }
}
break;
case SDL_VIDEORESIZE:
static void opt_frame_pix_fmt(const char *arg)
{
- frame_pix_fmt = avcodec_get_pix_fmt(arg);
+ frame_pix_fmt = av_get_pix_fmt(arg);
}
static int opt_sync(const char *opt, const char *arg)