* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
+#include "allformats.h"
#undef NDEBUG
#include <assert.h>
* Various utility functions for using ffmpeg library.
*/
+static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
+static void av_frac_add(AVFrac *f, int64_t incr);
+static void av_frac_set(AVFrac *f, int64_t val);
+
/** head of registered input format linked list. */
AVInputFormat *first_iformat = NULL;
/** head of registered output format linked list. */
int score_max, score;
/* specific test for image sequences */
+#ifdef CONFIG_IMAGE2_MUXER
if (!short_name && filename &&
filename_number_test(filename) >= 0 &&
av_guess_image2_codec(filename) != CODEC_ID_NONE) {
return guess_format("image2", NULL, NULL);
}
+#endif
if (!short_name && filename &&
filename_number_test(filename) >= 0 &&
guess_image_format(filename)) {
if(type == CODEC_TYPE_VIDEO){
enum CodecID codec_id= CODEC_ID_NONE;
+#ifdef CONFIG_IMAGE2_MUXER
if(!strcmp(fmt->name, "image2") || !strcmp(fmt->name, "image2pipe")){
codec_id= av_guess_image2_codec(filename);
}
+#endif
if(codec_id == CODEC_ID_NONE)
codec_id= fmt->video_codec;
return codec_id;
}
}
-void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr)
+void fifo_write(FifoBuffer *f, const uint8_t *buf, int size, uint8_t **wptr_ptr)
{
int len;
uint8_t *wptr;
/** Size of probe buffer, for guessing file type from file contents. */
#define PROBE_BUF_MIN 2048
-#define PROBE_BUF_MAX 131072
+#define PROBE_BUF_MAX (1<<20)
/**
* Open a media file as input. The codec are not opened. Only the file
/* XXX: suppress this hack for redirectors */
#ifdef CONFIG_NETWORK
- if (fmt == &redir_demux) {
+ if (fmt == &redir_demuxer) {
err = redir_open(ic_ptr, pb);
url_fclose(pb);
return err;
int frame_size;
if (enc->frame_size <= 1) {
- /* specific hack for pcm codecs because no frame size is
- provided */
- switch(enc->codec_id) {
- case CODEC_ID_PCM_S32LE:
- case CODEC_ID_PCM_S32BE:
- case CODEC_ID_PCM_U32LE:
- case CODEC_ID_PCM_U32BE:
- if (enc->channels == 0)
- return -1;
- frame_size = size / (4 * enc->channels);
- break;
- case CODEC_ID_PCM_S24LE:
- case CODEC_ID_PCM_S24BE:
- case CODEC_ID_PCM_U24LE:
- case CODEC_ID_PCM_U24BE:
- case CODEC_ID_PCM_S24DAUD:
- if (enc->channels == 0)
- return -1;
- frame_size = size / (3 * enc->channels);
- break;
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_U16BE:
- if (enc->channels == 0)
- return -1;
- frame_size = size / (2 * enc->channels);
- break;
- case CODEC_ID_PCM_S8:
- case CODEC_ID_PCM_U8:
- case CODEC_ID_PCM_MULAW:
- case CODEC_ID_PCM_ALAW:
+ int bits_per_sample = av_get_bits_per_sample(enc->codec_id);
+
+ if (bits_per_sample) {
if (enc->channels == 0)
return -1;
- frame_size = size / (enc->channels);
- break;
- default:
+ frame_size = (size << 3) / (bits_per_sample * enc->channels);
+ } else {
/* used for example by ADPCM codecs */
if (enc->bit_rate == 0)
return -1;
frame_size = (size * 8 * enc->sample_rate) / enc->bit_rate;
- break;
}
} else {
frame_size = enc->frame_size;
*pkt = s->cur_pkt;
compute_pkt_fields(s, st, NULL, pkt);
s->cur_st = NULL;
- return 0;
+ break;
} else if (s->cur_len > 0 && st->discard < AVDISCARD_ALL) {
len = av_parser_parse(st->parser, st->codec, &pkt->data, &pkt->size,
s->cur_ptr, s->cur_len,
pkt->dts = st->parser->dts;
pkt->destruct = av_destruct_packet_nofree;
compute_pkt_fields(s, st, st->parser, pkt);
- return 0;
+ break;
}
} else {
/* free packet */
}
st = s->streams[s->cur_pkt.stream_index];
+ if(st->codec->debug & FF_DEBUG_PTS)
+ av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%lld, dts=%lld, size=%d\n",
+ s->cur_pkt.stream_index,
+ s->cur_pkt.pts,
+ s->cur_pkt.dts,
+ s->cur_pkt.size);
s->cur_st = st;
s->cur_ptr = s->cur_pkt.data;
}
}
}
+ if(st->codec->debug & FF_DEBUG_PTS)
+ av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%lld, dts=%lld, size=%d\n",
+ pkt->stream_index,
+ pkt->pts,
+ pkt->dts,
+ pkt->size);
+
+ return 0;
}
/**
* @param timestamp new dts expressed in time_base of param ref_st
* @param ref_st reference stream giving time_base of param timestamp
*/
-static void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){
+void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){
int i;
for(i = 0; i < s->nb_streams; i++) {
}
ic->file_size = file_size;
- if ((ic->iformat == &mpegps_demux || ic->iformat == &mpegts_demux) && file_size && !ic->pb.is_streamed) {
+ if ((!strcmp(ic->iformat->name, "mpeg") ||
+ !strcmp(ic->iformat->name, "mpegts")) &&
+ file_size && !ic->pb.is_streamed) {
/* get accurate estimate from the PTSes */
av_estimate_timings_from_pts(ic);
} else if (av_has_timings(ic)) {
#define MAX_READ_SIZE 5000000
/* maximum duration until we stop analysing the stream */
-#define MAX_STREAM_DURATION ((int)(AV_TIME_BASE * 2.0))
+#define MAX_STREAM_DURATION ((int)(AV_TIME_BASE * 3.0))
/**
* Read the beginning of a media file to get stream information. This
char buf[256];
avcodec_string(buf, sizeof(buf), st->codec, 0);
av_log(ic, AV_LOG_INFO, "Could not find codec parameters (%s)\n", buf);
- break;
+ } else {
+ ret = 0;
}
}
- if (i == ic->nb_streams)
- ret = 0;
break;
}
int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
if(i){
st->codec->extradata_size= i;
- st->codec->extradata= av_malloc(st->codec->extradata_size);
+ st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size);
+ memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE);
}
}
av_parser_close(st->parser);
}
av_free(st->index_entries);
+ av_free(st->codec->extradata);
av_free(st->codec);
av_free(st);
}
int ret;
ret=compute_pkt_fields2(s->streams[pkt->stream_index], pkt);
- if(ret<0)
+ if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
return ret;
truncate_ts(s->streams[pkt->stream_index], pkt);
* packets with pkt->destruct == av_destruct_packet will be freed inside this function.
* so they cannot be used after it, note calling av_free_packet() on them is still safe
*/
-static int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
+int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){
AVPacketList *pktl, **next_point, *this_pktl;
int stream_count=0;
int streams[MAX_STREAMS];
return 0;
//av_log(NULL, AV_LOG_DEBUG, "av_interleaved_write_frame %d %Ld %Ld\n", pkt->size, pkt->dts, pkt->pts);
- if(compute_pkt_fields2(st, pkt) < 0)
+ if(compute_pkt_fields2(st, pkt) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
return -1;
if(pkt->dts == AV_NOPTS_VALUE)
av_log(NULL, AV_LOG_INFO, "(%s)", st->language);
}
av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den/g);
+ av_log(NULL, AV_LOG_INFO, ": %s", buf);
if(st->codec->codec_type == CODEC_TYPE_VIDEO){
if(st->r_frame_rate.den && st->r_frame_rate.num)
av_log(NULL, AV_LOG_INFO, ", %5.2f fps(r)", av_q2d(st->r_frame_rate));
else
av_log(NULL, AV_LOG_INFO, ", %5.2f fps(c)", 1/av_q2d(st->codec->time_base));
}
- av_log(NULL, AV_LOG_INFO, ": %s\n", buf);
+ av_log(NULL, AV_LOG_INFO, "\n");
}
}
}
else {
/* Finally we give up and parse it as double */
- *frame_rate_base = DEFAULT_FRAME_RATE_BASE; //FIXME use av_d2q()
- *frame_rate = (int)(strtod(arg, 0) * (*frame_rate_base) + 0.5);
+ AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE);
+ *frame_rate_base = time_base.den;
+ *frame_rate = time_base.num;
}
if (!*frame_rate || !*frame_rate_base)
return -1;
* @param num must be >= 0
* @param den must be >= 1
*/
-void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
+static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
{
num += (den >> 1);
if (num >= den) {
/**
* Set f to (val + 0.5).
*/
-void av_frac_set(AVFrac *f, int64_t val)
+static void av_frac_set(AVFrac *f, int64_t val)
{
f->val = val;
f->num = f->den >> 1;
* @param f fractional number
* @param incr increment, can be positive or negative
*/
-void av_frac_add(AVFrac *f, int64_t incr)
+static void av_frac_add(AVFrac *f, int64_t incr)
{
int64_t num, den;