Пример #1
0
static int gxf_write_umf_media_description(AVFormatContext *s)
{
    GXFContext *gxf = s->priv_data;
    ByteIOContext *pb = s->pb;
    int64_t pos;
    int i, j;

    pos = url_ftell(pb);
    gxf->umf_media_offset = pos - gxf->umf_start_offset;
    for (i = 0; i <= s->nb_streams; ++i) {
        GXFStreamContext *sc;
        int64_t startpos, curpos;

        if (i == s->nb_streams)
            sc = &gxf->timecode_track;
        else
            sc = s->streams[i]->priv_data;

        startpos = url_ftell(pb);
        put_le16(pb, 0); /* length */
        put_le16(pb, sc->media_info);
        put_le16(pb, 0); /* reserved */
        put_le16(pb, 0); /* reserved */
        put_le32(pb, gxf->nb_fields);
        put_le32(pb, 0); /* attributes rw, ro */
        put_le32(pb, 0); /* mark in */
        put_le32(pb, gxf->nb_fields); /* mark out */
        put_buffer(pb, ES_NAME_PATTERN, strlen(ES_NAME_PATTERN));
        put_be16(pb, sc->media_info);
        for (j = strlen(ES_NAME_PATTERN)+2; j < 88; j++)
            put_byte(pb, 0);
        put_le32(pb, sc->track_type);
        put_le32(pb, sc->sample_rate);
        put_le32(pb, sc->sample_size);
        put_le32(pb, 0); /* reserved */

        if (sc == &gxf->timecode_track)
            gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */
        else {
            AVStream *st = s->streams[i];
            switch (st->codec->codec_id) {
            case CODEC_ID_MPEG2VIDEO:
                gxf_write_umf_media_mpeg(pb, st);
                break;
            case CODEC_ID_PCM_S16LE:
                gxf_write_umf_media_audio(pb, sc);
                break;
            case CODEC_ID_DVVIDEO:
                gxf_write_umf_media_dv(pb, sc);
                break;
            }
        }

        curpos = url_ftell(pb);
        url_fseek(pb, startpos, SEEK_SET);
        put_le16(pb, curpos - startpos);
        url_fseek(pb, curpos, SEEK_SET);
    }
    return url_ftell(pb) - pos;
}
Пример #2
0
static int gxf_write_umf_media_description(ByteIOContext *pb, GXFContext *ctx)
{
    int64_t pos;
    int i;

    pos = url_ftell(pb);
    ctx->umf_media_offset = pos - ctx->umf_start_offset;
    for (i = 0; i < ctx->fc->nb_streams; ++i) {
        GXFStreamContext *sc = &ctx->streams[i];
        char buffer[88];
        int64_t startpos, curpos;
        int path_size = strlen(ES_NAME_PATTERN);

        memset(buffer, 0, 88);
        startpos = url_ftell(pb);
        put_le16(pb, 0); /* length */
        put_le16(pb, sc->media_info);
        put_le16(pb, 0); /* reserved */
        put_le16(pb, 0); /* reserved */
        put_le32(pb, ctx->nb_frames);
        put_le32(pb, 0); /* attributes rw, ro */
        put_le32(pb, 0); /* mark in */
        put_le32(pb, ctx->nb_frames); /* mark out */
        strncpy(buffer, ES_NAME_PATTERN, path_size);
        put_buffer(pb, (uint8_t *)buffer, path_size);
        put_be16(pb, sc->media_info);
        put_buffer(pb, (uint8_t *)buffer + path_size + 2, 88 - path_size - 2);
        put_le32(pb, sc->track_type);
        put_le32(pb, sc->sample_rate);
        put_le32(pb, sc->sample_size);
        put_le32(pb, 0); /* reserved */
        switch (sc->codec->codec_id) {
        case CODEC_ID_MPEG2VIDEO:
            gxf_write_umf_media_mpeg(pb, sc);
            break;
        case CODEC_ID_PCM_S16LE:
            gxf_write_umf_media_audio(pb, sc);
            break;
        case CODEC_ID_DVVIDEO:
            gxf_write_umf_media_dv(pb, sc);
            break;
        default:
            gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */
        }
        curpos = url_ftell(pb);
        url_fseek(pb, startpos, SEEK_SET);
        put_le16(pb, curpos - startpos);
        url_fseek(pb, curpos, SEEK_SET);
    }
    return url_ftell(pb) - pos;
}