static int gxf_write_eos_packet(AVIOContext *pb) { int64_t pos = avio_tell(pb); gxf_write_packet_header(pb, PKT_EOS); return updatePacketSize(pb, pos); }
static int gxf_write_map_packet(AVFormatContext *s, int rewrite) { GXFContext *gxf = s->priv_data; AVIOContext *pb = s->pb; int64_t pos = avio_tell(pb); if (!rewrite) { if (!(gxf->map_offsets_nb % 30)) { gxf->map_offsets = av_realloc_f(gxf->map_offsets, sizeof(*gxf->map_offsets), gxf->map_offsets_nb+30); if (!gxf->map_offsets) { av_log(s, AV_LOG_ERROR, "could not realloc map offsets\n"); return -1; } } gxf->map_offsets[gxf->map_offsets_nb++] = pos; // do not increment here } gxf_write_packet_header(pb, PKT_MAP); /* preamble */ avio_w8(pb, 0xE0); /* version */ avio_w8(pb, 0xFF); /* reserved */ gxf_write_material_data_section(s); gxf_write_track_description_section(s); return updatePacketSize(pb, pos); }
static int gxf_write_eos_packet(ByteIOContext *pb, GXFContext *ctx) { int64_t pos = url_ftell(pb); gxf_write_packet_header(pb, PKT_EOS); return updatePacketSize(pb, pos); }
static int gxf_write_flt_packet(AVFormatContext *s) { GXFContext *gxf = s->priv_data; AVIOContext *pb = s->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; gxf_write_packet_header(pb, PKT_FLT); avio_wl32(pb, fields_per_flt); /* number of fields */ avio_wl32(pb, flt_entries); /* number of active flt entries */ if (gxf->flt_entries) { for (i = 0; i < flt_entries; i++) avio_wl32(pb, gxf->flt_entries[(i*fields_per_flt)>>1]); } for (; i < 1000; i++) avio_wl32(pb, 0); return updatePacketSize(pb, pos); }
static int gxf_write_flt_packet(ByteIOContext *pb, GXFContext *ctx) { int64_t pos = url_ftell(pb); int i; gxf_write_packet_header(pb, PKT_FLT); put_le32(pb, 1000); /* number of fields */ put_le32(pb, 0); /* number of active flt entries */ for (i = 0; i < 1000; ++i) { put_le32(pb, 0); } return updatePacketSize(pb, pos); }
static int gxf_write_map_packet(ByteIOContext *pb, GXFContext *ctx) { int64_t pos = url_ftell(pb); gxf_write_packet_header(pb, PKT_MAP); /* preamble */ put_byte(pb, 0xE0); /* version */ put_byte(pb, 0xFF); /* reserved */ gxf_write_material_data_section(pb, ctx); gxf_write_track_description_section(pb, ctx); return updatePacketSize(pb, pos); }
static int gxf_write_media_packet(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt) { GXFStreamContext *sc = &ctx->streams[pkt->stream_index]; int64_t pos = url_ftell(pb); int padding = 0; gxf_write_packet_header(pb, PKT_MEDIA); if (sc->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ padding = 4 - pkt->size % 4; else if (sc->codec->codec_type == CODEC_TYPE_AUDIO) padding = GXF_AUDIO_PACKET_SIZE - pkt->size; gxf_write_media_preamble(pb, ctx, pkt, pkt->size + padding); put_buffer(pb, pkt->data, pkt->size); gxf_write_padding(pb, padding); return updatePacketSize(pb, pos); }
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 = avio_tell(pb); int padding = 0; 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 */ padding = 4 - pkt->size % 4; else if (st->codec->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 (!(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) { av_log(s, AV_LOG_ERROR, "could not reallocate flt entries\n"); return -1; } } gxf->flt_entries[gxf->flt_entries_nb++] = packet_start_offset; gxf->nb_fields += 2; // count fields } updatePacketSize(pb, pos); gxf->packet_count++; if (gxf->packet_count == 100) { gxf_write_map_packet(s, 0); gxf->packet_count = 0; } avio_flush(pb); return 0; }
static int gxf_write_umf_packet(ByteIOContext *pb, GXFContext *ctx) { int64_t pos = url_ftell(pb); gxf_write_packet_header(pb, PKT_UMF); /* preamble */ put_byte(pb, 3); /* first and last (only) packet */ put_be32(pb, ctx->umf_length); /* data length */ ctx->umf_start_offset = url_ftell(pb); gxf_write_umf_payload(pb, ctx); gxf_write_umf_material_description(pb, ctx); ctx->umf_track_size = gxf_write_umf_track_description(pb, ctx); ctx->umf_media_size = gxf_write_umf_media_description(pb, ctx); ctx->umf_user_data_size = gxf_write_umf_user_data(pb, ctx); ctx->umf_length = url_ftell(pb) - ctx->umf_start_offset; return updatePacketSize(pb, pos); }
static int gxf_write_umf_packet(AVFormatContext *s) { GXFContext *gxf = s->priv_data; AVIOContext *pb = s->pb; int64_t pos = avio_tell(pb); gxf_write_packet_header(pb, PKT_UMF); /* preamble */ avio_w8(pb, 3); /* first and last (only) packet */ avio_wb32(pb, gxf->umf_length); /* data length */ 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 = avio_tell(pb) - gxf->umf_start_offset; return updatePacketSize(pb, pos); }