X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fgxfenc.c;h=60f88fdabd726f3b7aa41c796120062610ac5bef;hb=46278ec90ac5ad1dab5e85991f176afe49003fee;hp=66accb3e088e4bde80b5b5c26a9718ff40014c4f;hpb=6b4aa5dac8f41aa452d0ce9a1bede9e59a303060;p=ffmpeg diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c index 66accb3e088..60f88fdabd7 100644 --- a/libavformat/gxfenc.c +++ b/libavformat/gxfenc.c @@ -2,26 +2,28 @@ * GXF muxer. * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/intfloat.h" +#include "libavutil/mathematics.h" #include "avformat.h" +#include "internal.h" #include "gxf.h" -#include "riff.h" #include "audiointerleave.h" #define GXF_AUDIO_PACKET_SIZE 65536 @@ -40,7 +42,7 @@ typedef struct GXFStreamContext { int pframes; int bframes; int p_per_gop; - int b_per_i_or_p; ///< number of B frames per I frame or P frame + int b_per_i_or_p; ///< number of B-frames per I-frame or P-frame int first_gop_closed; unsigned order; ///< interleaving order } GXFStreamContext; @@ -78,22 +80,22 @@ static const struct { }; static const AVCodecTag gxf_media_types[] = { - { CODEC_ID_MJPEG , 3 }, /* NTSC */ - { CODEC_ID_MJPEG , 4 }, /* PAL */ - { CODEC_ID_PCM_S24LE , 9 }, - { CODEC_ID_PCM_S16LE , 10 }, - { CODEC_ID_MPEG2VIDEO, 11 }, /* NTSC */ - { CODEC_ID_MPEG2VIDEO, 12 }, /* PAL */ - { CODEC_ID_DVVIDEO , 13 }, /* NTSC */ - { CODEC_ID_DVVIDEO , 14 }, /* PAL */ - { CODEC_ID_DVVIDEO , 15 }, /* 50M NTSC */ - { CODEC_ID_DVVIDEO , 16 }, /* 50M PAL */ - { CODEC_ID_AC3 , 17 }, - //{ CODEC_ID_NONE, , 18 }, /* Non compressed 24 bit audio */ - { CODEC_ID_MPEG2VIDEO, 20 }, /* MPEG HD */ - { CODEC_ID_MPEG1VIDEO, 22 }, /* NTSC */ - { CODEC_ID_MPEG1VIDEO, 23 }, /* PAL */ - { CODEC_ID_NONE, 0 }, + { AV_CODEC_ID_MJPEG , 3 }, /* NTSC */ + { AV_CODEC_ID_MJPEG , 4 }, /* PAL */ + { AV_CODEC_ID_PCM_S24LE , 9 }, + { AV_CODEC_ID_PCM_S16LE , 10 }, + { AV_CODEC_ID_MPEG2VIDEO, 11 }, /* NTSC */ + { AV_CODEC_ID_MPEG2VIDEO, 12 }, /* PAL */ + { AV_CODEC_ID_DVVIDEO , 13 }, /* NTSC */ + { AV_CODEC_ID_DVVIDEO , 14 }, /* PAL */ + { AV_CODEC_ID_DVVIDEO , 15 }, /* 50M NTSC */ + { AV_CODEC_ID_DVVIDEO , 16 }, /* 50M PAL */ + { AV_CODEC_ID_AC3 , 17 }, + //{ AV_CODEC_ID_NONE, , 18 }, /* Non compressed 24 bit audio */ + { AV_CODEC_ID_MPEG2VIDEO, 20 }, /* MPEG HD */ + { AV_CODEC_ID_MPEG1VIDEO, 22 }, /* NTSC */ + { AV_CODEC_ID_MPEG1VIDEO, 23 }, /* PAL */ + { AV_CODEC_ID_NONE, 0 }, }; #define SERVER_PATH "EXT:/PDR/default/" @@ -105,7 +107,7 @@ static int gxf_find_lines_index(AVStream *st) int i; for (i = 0; i < 6; ++i) { - if (st->codec->height == gxf_lines_tab[i].height) { + if (st->codecpar->height == gxf_lines_tab[i].height) { sc->lines_index = gxf_lines_tab[i].index; return 0; } @@ -125,12 +127,12 @@ static int64_t updatePacketSize(AVIOContext *pb, int64_t pos) int64_t curpos; int size; - size = url_ftell(pb) - pos; + size = avio_tell(pb) - pos; if (size % 4) { gxf_write_padding(pb, 4 - size % 4); - size = url_ftell(pb) - pos; + size = avio_tell(pb) - pos; } - curpos = url_ftell(pb); + curpos = avio_tell(pb); avio_seek(pb, pos + 6, SEEK_SET); avio_wb32(pb, size); avio_seek(pb, curpos, SEEK_SET); @@ -141,7 +143,7 @@ static int64_t updateSize(AVIOContext *pb, int64_t pos) { int64_t curpos; - curpos = url_ftell(pb); + curpos = avio_tell(pb); avio_seek(pb, pos, SEEK_SET); avio_wb16(pb, curpos - pos - 2); avio_seek(pb, curpos, SEEK_SET); @@ -179,18 +181,18 @@ static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st) if (sc->b_per_i_or_p > 9) sc->b_per_i_or_p = 9; /* ensure value won't take more than one char */ } - if (st->codec->height == 512 || st->codec->height == 608) + if (st->codecpar->height == 512 || st->codecpar->height == 608) starting_line = 7; // VBI - else if (st->codec->height == 480) + else if (st->codecpar->height == 480) starting_line = 20; else starting_line = 23; // default PAL size = snprintf(buffer, 1024, "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n" "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n", - (float)st->codec->bit_rate, sc->p_per_gop, sc->b_per_i_or_p, - st->codec->pix_fmt == PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1, - starting_line, (st->codec->height + 15) / 16); + (float)st->codecpar->bit_rate, sc->p_per_gop, sc->b_per_i_or_p, + st->codecpar->format == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1, + starting_line, (st->codecpar->height + 15) / 16); avio_w8(pb, TRACK_MPG_AUX); avio_w8(pb, size + 1); avio_write(pb, (uint8_t *)buffer, size + 1); @@ -218,7 +220,7 @@ static int gxf_write_track_description(AVFormatContext *s, GXFStreamContext *sc, avio_w8(pb, sc->media_type + 0x80); avio_w8(pb, index + 0xC0); - pos = url_ftell(pb); + pos = avio_tell(pb); avio_wb16(pb, 0); /* size */ /* media file name */ @@ -272,7 +274,7 @@ static int gxf_write_material_data_section(AVFormatContext *s) int len; const char *filename = strrchr(s->filename, '/'); - pos = url_ftell(pb); + pos = avio_tell(pb); avio_wb16(pb, 0); /* size */ /* name */ @@ -310,7 +312,7 @@ static int gxf_write_material_data_section(AVFormatContext *s) /* estimated size */ avio_w8(pb, MAT_SIZE); avio_w8(pb, 4); - avio_wb32(pb, url_fsize(pb) / 1024); + avio_wb32(pb, avio_size(pb) / 1024); return updateSize(pb, pos); } @@ -322,7 +324,7 @@ static int gxf_write_track_description_section(AVFormatContext *s) int64_t pos; int i; - pos = url_ftell(pb); + pos = avio_tell(pb); avio_wb16(pb, 0); /* size */ for (i = 0; i < s->nb_streams; ++i) gxf_write_track_description(s, s->streams[i]->priv_data, i); @@ -336,15 +338,17 @@ static int gxf_write_map_packet(AVFormatContext *s, int rewrite) { GXFContext *gxf = s->priv_data; AVIOContext *pb = s->pb; - int64_t pos = url_ftell(pb); + int64_t pos = avio_tell(pb); if (!rewrite) { if (!(gxf->map_offsets_nb % 30)) { - gxf->map_offsets = av_realloc(gxf->map_offsets, - (gxf->map_offsets_nb+30)*sizeof(*gxf->map_offsets)); - if (!gxf->map_offsets) { + int err; + if ((err = av_reallocp_array(&gxf->map_offsets, + gxf->map_offsets_nb + 30, + sizeof(*gxf->map_offsets))) < 0) { + gxf->map_offsets_nb = 0; av_log(s, AV_LOG_ERROR, "could not realloc map offsets\n"); - return -1; + return err; } } gxf->map_offsets[gxf->map_offsets_nb++] = pos; // do not increment here @@ -366,7 +370,7 @@ static int gxf_write_flt_packet(AVFormatContext *s) { GXFContext *gxf = s->priv_data; AVIOContext *pb = s->pb; - int64_t pos = url_ftell(pb); + int64_t pos = avio_tell(pb); int fields_per_flt = (gxf->nb_fields+1) / 1000 + 1; int flt_entries = gxf->nb_fields / fields_per_flt; int i = 0; @@ -392,9 +396,15 @@ static int gxf_write_umf_material_description(AVFormatContext *s) GXFContext *gxf = s->priv_data; AVIOContext *pb = s->pb; int timecode_base = gxf->time_base.den == 60000 ? 60 : 50; + int64_t timestamp = 0; + AVDictionaryEntry *t; + uint32_t timecode; + + if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) + timestamp = ff_iso8601_to_unix_time(t->value); // XXX drop frame - uint32_t timecode = + timecode = gxf->nb_fields / (timecode_base * 3600) % 24 << 24 | // hours gxf->nb_fields / (timecode_base * 60) % 60 << 16 | // minutes gxf->nb_fields / timecode_base % 60 << 8 | // seconds @@ -407,8 +417,8 @@ static int gxf_write_umf_material_description(AVFormatContext *s) avio_wl32(pb, gxf->nb_fields); /* mark out */ avio_wl32(pb, 0); /* timecode mark in */ avio_wl32(pb, timecode); /* timecode mark out */ - avio_wl64(pb, s->timestamp); /* modification time */ - avio_wl64(pb, s->timestamp); /* creation time */ + avio_wl64(pb, timestamp); /* modification time */ + avio_wl64(pb, timestamp); /* creation time */ avio_wl16(pb, 0); /* reserved */ avio_wl16(pb, 0); /* reserved */ avio_wl16(pb, gxf->audio_tracks); @@ -442,7 +452,7 @@ static int gxf_write_umf_track_description(AVFormatContext *s) { AVIOContext *pb = s->pb; GXFContext *gxf = s->priv_data; - int64_t pos = url_ftell(pb); + int64_t pos = avio_tell(pb); int i; gxf->umf_track_offset = pos - gxf->umf_start_offset; @@ -455,14 +465,14 @@ static int gxf_write_umf_track_description(AVFormatContext *s) avio_wl16(pb, gxf->timecode_track.media_info); avio_wl16(pb, 1); - return url_ftell(pb) - pos; + return avio_tell(pb) - pos; } static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st) { GXFStreamContext *sc = st->priv_data; - if (st->codec->pix_fmt == PIX_FMT_YUV422P) + if (st->codecpar->format == AV_PIX_FMT_YUV422P) avio_wl32(pb, 2); else avio_wl32(pb, 1); /* default to 420 */ @@ -471,9 +481,9 @@ static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st) avio_wl32(pb, 1); /* I picture per GOP */ avio_wl32(pb, sc->p_per_gop); avio_wl32(pb, sc->b_per_i_or_p); - if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) avio_wl32(pb, 2); - else if (st->codec->codec_id == CODEC_ID_MPEG1VIDEO) + else if (st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO) avio_wl32(pb, 1); else avio_wl32(pb, 0); @@ -506,8 +516,8 @@ static int gxf_write_umf_media_dv(AVIOContext *pb, GXFStreamContext *sc) static int gxf_write_umf_media_audio(AVIOContext *pb, GXFStreamContext *sc) { - avio_wl64(pb, av_dbl2int(1)); /* sound level to begin to */ - avio_wl64(pb, av_dbl2int(1)); /* sound level to begin to */ + avio_wl64(pb, av_double2int(1)); /* sound level to begin to */ + avio_wl64(pb, av_double2int(1)); /* sound level to begin to */ avio_wl32(pb, 0); /* number of fields over which to ramp up sound level */ avio_wl32(pb, 0); /* number of fields over which to ramp down sound level */ avio_wl32(pb, 0); /* reserved */ @@ -515,17 +525,6 @@ static int gxf_write_umf_media_audio(AVIOContext *pb, GXFStreamContext *sc) return 32; } -#if 0 -static int gxf_write_umf_media_mjpeg(AVIOContext *pb, GXFStreamContext *sc) -{ - avio_wb64(pb, 0); /* FIXME FLOAT max chroma quant level */ - avio_wb64(pb, 0); /* FIXME FLOAT max luma quant level */ - avio_wb64(pb, 0); /* FIXME FLOAT min chroma quant level */ - avio_wb64(pb, 0); /* FIXME FLOAT min luma quant level */ - return 32; -} -#endif - static int gxf_write_umf_media_description(AVFormatContext *s) { GXFContext *gxf = s->priv_data; @@ -533,7 +532,7 @@ static int gxf_write_umf_media_description(AVFormatContext *s) int64_t pos; int i, j; - pos = url_ftell(pb); + pos = avio_tell(pb); gxf->umf_media_offset = pos - gxf->umf_start_offset; for (i = 0; i <= s->nb_streams; ++i) { GXFStreamContext *sc; @@ -544,7 +543,7 @@ static int gxf_write_umf_media_description(AVFormatContext *s) else sc = s->streams[i]->priv_data; - startpos = url_ftell(pb); + startpos = avio_tell(pb); avio_wl16(pb, 0); /* length */ avio_wl16(pb, sc->media_info); avio_wl16(pb, 0); /* reserved */ @@ -566,33 +565,33 @@ static int gxf_write_umf_media_description(AVFormatContext *s) gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */ else { AVStream *st = s->streams[i]; - switch (st->codec->codec_id) { - case CODEC_ID_MPEG1VIDEO: - case CODEC_ID_MPEG2VIDEO: + switch (st->codecpar->codec_id) { + case AV_CODEC_ID_MPEG1VIDEO: + case AV_CODEC_ID_MPEG2VIDEO: gxf_write_umf_media_mpeg(pb, st); break; - case CODEC_ID_PCM_S16LE: + case AV_CODEC_ID_PCM_S16LE: gxf_write_umf_media_audio(pb, sc); break; - case CODEC_ID_DVVIDEO: + case AV_CODEC_ID_DVVIDEO: gxf_write_umf_media_dv(pb, sc); break; } } - curpos = url_ftell(pb); + curpos = avio_tell(pb); avio_seek(pb, startpos, SEEK_SET); avio_wl16(pb, curpos - startpos); avio_seek(pb, curpos, SEEK_SET); } - return url_ftell(pb) - pos; + return avio_tell(pb) - pos; } static int gxf_write_umf_packet(AVFormatContext *s) { GXFContext *gxf = s->priv_data; AVIOContext *pb = s->pb; - int64_t pos = url_ftell(pb); + int64_t pos = avio_tell(pb); gxf_write_packet_header(pb, PKT_UMF); @@ -600,12 +599,12 @@ static int gxf_write_umf_packet(AVFormatContext *s) avio_w8(pb, 3); /* first and last (only) packet */ avio_wb32(pb, gxf->umf_length); /* data length */ - gxf->umf_start_offset = url_ftell(pb); + gxf->umf_start_offset = avio_tell(pb); gxf_write_umf_payload(s); gxf_write_umf_material_description(s); gxf->umf_track_size = gxf_write_umf_track_description(s); gxf->umf_media_size = gxf_write_umf_media_description(s); - gxf->umf_length = url_ftell(pb) - gxf->umf_start_offset; + gxf->umf_length = avio_tell(pb) - gxf->umf_start_offset; return updatePacketSize(pb, pos); } @@ -634,7 +633,7 @@ static int gxf_write_header(AVFormatContext *s) uint8_t tracks[255] = {0}; int i, media_info = 0; - if (url_is_streamed(pb)) { + if (!pb->seekable) { av_log(s, AV_LOG_ERROR, "gxf muxer does not support streamed output, patch welcome"); return -1; } @@ -647,23 +646,23 @@ static int gxf_write_header(AVFormatContext *s) return AVERROR(ENOMEM); st->priv_data = sc; - sc->media_type = ff_codec_get_tag(gxf_media_types, st->codec->codec_id); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codec->codec_id != CODEC_ID_PCM_S16LE) { + sc->media_type = ff_codec_get_tag(gxf_media_types, st->codecpar->codec_id); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE) { av_log(s, AV_LOG_ERROR, "only 16 BIT PCM LE allowed for now\n"); return -1; } - if (st->codec->sample_rate != 48000) { + if (st->codecpar->sample_rate != 48000) { av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n"); return -1; } - if (st->codec->channels != 1) { + if (st->codecpar->channels != 1) { av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n"); return -1; } sc->track_type = 2; - sc->sample_rate = st->codec->sample_rate; - av_set_pts_info(st, 64, 1, sc->sample_rate); + sc->sample_rate = st->codecpar->sample_rate; + avpriv_set_pts_info(st, 64, 1, sc->sample_rate); sc->sample_size = 16; sc->frame_rate_index = -2; sc->lines_index = -2; @@ -671,18 +670,18 @@ static int gxf_write_header(AVFormatContext *s) gxf->audio_tracks++; gxf->flags |= 0x04000000; /* audio is 16 bit pcm */ media_info = 'A'; - } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (i != 0) { av_log(s, AV_LOG_ERROR, "video stream must be the first track\n"); return -1; } /* FIXME check from time_base ? */ - if (st->codec->height == 480 || st->codec->height == 512) { /* NTSC or NTSC+VBI */ + if (st->codecpar->height == 480 || st->codecpar->height == 512) { /* NTSC or NTSC+VBI */ sc->frame_rate_index = 5; sc->sample_rate = 60; gxf->flags |= 0x00000080; gxf->time_base = (AVRational){ 1001, 60000 }; - } else if (st->codec->height == 576 || st->codec->height == 608) { /* PAL or PAL+VBI */ + } else if (st->codecpar->height == 576 || st->codecpar->height == 608) { /* PAL or PAL+VBI */ sc->frame_rate_index = 6; sc->media_type++; sc->sample_rate = 50; @@ -693,34 +692,34 @@ static int gxf_write_header(AVFormatContext *s) "gxf muxer only accepts PAL or NTSC resolutions currently\n"); return -1; } - av_set_pts_info(st, 64, gxf->time_base.num, gxf->time_base.den); + avpriv_set_pts_info(st, 64, gxf->time_base.num, gxf->time_base.den); if (gxf_find_lines_index(st) < 0) sc->lines_index = -1; - sc->sample_size = st->codec->bit_rate; + sc->sample_size = st->codecpar->bit_rate; sc->fields = 2; /* interlaced */ vsc = sc; - switch (st->codec->codec_id) { - case CODEC_ID_MJPEG: + switch (st->codecpar->codec_id) { + case AV_CODEC_ID_MJPEG: sc->track_type = 1; gxf->flags |= 0x00004000; media_info = 'J'; break; - case CODEC_ID_MPEG1VIDEO: + case AV_CODEC_ID_MPEG1VIDEO: sc->track_type = 9; gxf->mpeg_tracks++; media_info = 'L'; break; - case CODEC_ID_MPEG2VIDEO: + case AV_CODEC_ID_MPEG2VIDEO: sc->first_gop_closed = -1; sc->track_type = 4; gxf->mpeg_tracks++; gxf->flags |= 0x00008000; media_info = 'M'; break; - case CODEC_ID_DVVIDEO: - if (st->codec->pix_fmt == PIX_FMT_YUV422P) { + case AV_CODEC_ID_DVVIDEO: + if (st->codecpar->format == AV_PIX_FMT_YUV422P) { sc->media_type += 2; sc->track_type = 6; gxf->flags |= 0x00002000; @@ -753,13 +752,13 @@ static int gxf_write_header(AVFormatContext *s) gxf->packet_count = 3; - put_flush_packet(pb); + avio_flush(pb); return 0; } static int gxf_write_eos_packet(AVIOContext *pb) { - int64_t pos = url_ftell(pb); + int64_t pos = avio_tell(pb); gxf_write_packet_header(pb, PKT_EOS); return updatePacketSize(pb, pos); @@ -775,18 +774,18 @@ static int gxf_write_trailer(AVFormatContext *s) ff_audio_interleave_close(s); gxf_write_eos_packet(pb); - end = url_ftell(pb); + end = avio_tell(pb); avio_seek(pb, 0, SEEK_SET); /* overwrite map, flt and umf packets with new values */ gxf_write_map_packet(s, 1); gxf_write_flt_packet(s); gxf_write_umf_packet(s); - put_flush_packet(pb); + avio_flush(pb); /* update duration in all map packets */ for (i = 1; i < gxf->map_offsets_nb; i++) { avio_seek(pb, gxf->map_offsets[i], SEEK_SET); gxf_write_map_packet(s, 1); - put_flush_packet(pb); + avio_flush(pb); } avio_seek(pb, end, SEEK_SET); @@ -819,7 +818,7 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) /* If the video is frame-encoded, the frame numbers shall be represented by * even field numbers. * see SMPTE360M-2004 6.4.2.1.3 Media field number */ - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { field_nb = gxf->nb_fields; } else { field_nb = av_rescale_rnd(pkt->dts, gxf->time_base.den, @@ -829,15 +828,15 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) avio_w8(pb, sc->media_type); avio_w8(pb, st->index); avio_wb32(pb, field_nb); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { avio_wb16(pb, 0); avio_wb16(pb, size / 2); - } else if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) { int frame_type = gxf_parse_mpeg_frame(sc, pkt->data, pkt->size); - if (frame_type == FF_I_TYPE) { + if (frame_type == AV_PICTURE_TYPE_I) { avio_w8(pb, 0x0d); sc->iframes++; - } else if (frame_type == FF_B_TYPE) { + } else if (frame_type == AV_PICTURE_TYPE_B) { avio_w8(pb, 0x0f); sc->bframes++; } else { @@ -845,7 +844,7 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) sc->pframes++; } avio_wb24(pb, size); - } else if (st->codec->codec_id == CODEC_ID_DVVIDEO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) { avio_w8(pb, size / 4096); avio_wb24(pb, 0); } else @@ -861,26 +860,28 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) GXFContext *gxf = s->priv_data; AVIOContext *pb = s->pb; AVStream *st = s->streams[pkt->stream_index]; - int64_t pos = url_ftell(pb); + int64_t pos = avio_tell(pb); int padding = 0; - int packet_start_offset = url_ftell(pb) / 1024; + int packet_start_offset = avio_tell(pb) / 1024; gxf_write_packet_header(pb, PKT_MEDIA); - if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ padding = 4 - pkt->size % 4; - else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) padding = GXF_AUDIO_PACKET_SIZE - pkt->size; gxf_write_media_preamble(s, pkt, pkt->size + padding); avio_write(pb, pkt->data, pkt->size); gxf_write_padding(pb, padding); - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (!(gxf->flt_entries_nb % 500)) { - gxf->flt_entries = av_realloc(gxf->flt_entries, - (gxf->flt_entries_nb+500)*sizeof(*gxf->flt_entries)); - if (!gxf->flt_entries) { + int err; + if ((err = av_reallocp_array(&gxf->flt_entries, + gxf->flt_entries_nb + 500, + sizeof(*gxf->flt_entries))) < 0) { + gxf->flt_entries_nb = 0; av_log(s, AV_LOG_ERROR, "could not reallocate flt entries\n"); - return -1; + return err; } } gxf->flt_entries[gxf->flt_entries_nb++] = packet_start_offset; @@ -895,8 +896,6 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) gxf->packet_count = 0; } - put_flush_packet(pb); - return 0; } @@ -910,7 +909,7 @@ static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cu for (i = 0; i < 2; i++) { AVStream *st = s->streams[pkt[i]->stream_index]; sc[i] = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { field_nb[i] = av_rescale_rnd(pkt[i]->dts, gxf->time_base.den, (int64_t)48000*gxf->time_base.num, AV_ROUND_UP); field_nb[i] &= ~1; // compare against even field number because audio must be before video @@ -924,24 +923,21 @@ static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cu static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - if (pkt && s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (pkt && s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) pkt->duration = 2; // enforce 2 fields return ff_audio_rechunk_interleave(s, out, pkt, flush, - av_interleave_packet_per_dts, gxf_compare_field_nb); + ff_interleave_packet_per_dts, gxf_compare_field_nb); } AVOutputFormat ff_gxf_muxer = { - "gxf", - NULL_IF_CONFIG_SMALL("GXF format"), - NULL, - "gxf", - sizeof(GXFContext), - CODEC_ID_PCM_S16LE, - CODEC_ID_MPEG2VIDEO, - gxf_write_header, - gxf_write_packet, - gxf_write_trailer, - 0, - NULL, - gxf_interleave_packet, + .name = "gxf", + .long_name = NULL_IF_CONFIG_SMALL("GXF (General eXchange Format)"), + .extensions = "gxf", + .priv_data_size = sizeof(GXFContext), + .audio_codec = AV_CODEC_ID_PCM_S16LE, + .video_codec = AV_CODEC_ID_MPEG2VIDEO, + .write_header = gxf_write_header, + .write_packet = gxf_write_packet, + .write_trailer = gxf_write_trailer, + .interleave_packet = gxf_interleave_packet, };