Ejemplo n.º 1
0
Archivo: r3d.c Proyecto: mmaker/FFmpeg
static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
{
    AVStream *st = s->streams[1];
    int av_unused tmp, tmp2;
    int samples, size;
    uint64_t pos = avio_tell(s->pb);
    unsigned dts;
    int ret;

    dts = avio_rb32(s->pb);

    st->codec->sample_rate = avio_rb32(s->pb);

    samples = avio_rb32(s->pb);

    tmp = avio_rb32(s->pb);
    av_dlog(s, "packet num %d\n", tmp);

    tmp = avio_rb16(s->pb); // unknown
    av_dlog(s, "unknown %d\n", tmp);

    tmp  = avio_r8(s->pb); // major version
    tmp2 = avio_r8(s->pb); // minor version
    av_dlog(s, "version %d.%d\n", tmp, tmp2);

    tmp = avio_rb32(s->pb); // unknown
    av_dlog(s, "unknown %d\n", tmp);

    size = atom->size - 8 - (avio_tell(s->pb) - pos);
    if (size < 0)
        return -1;
    ret = av_get_packet(s->pb, pkt, size);
    if (ret < 0) {
        av_log(s, AV_LOG_ERROR, "error reading audio packet\n");
        return ret;
    }

    pkt->stream_index = 1;
    pkt->dts = dts;
    pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate);
    av_dlog(s, "pkt dts %"PRId64" duration %d samples %d sample rate %d\n",
            pkt->dts, pkt->duration, samples, st->codec->sample_rate);

    return 0;
}
Ejemplo n.º 2
0
static int wsaud_read_packet(AVFormatContext *s,
                             AVPacket *pkt)
{
    AVIOContext *pb = s->pb;
    unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
    unsigned int chunk_size;
    int ret = 0;
    AVStream *st = s->streams[0];

    if (avio_read(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) !=
        AUD_CHUNK_PREAMBLE_SIZE)
        return AVERROR(EIO);

    /* validate the chunk */
    if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE)
        return AVERROR_INVALIDDATA;

    chunk_size = AV_RL16(&preamble[0]);

    if (st->codec->codec_id == AV_CODEC_ID_WESTWOOD_SND1) {
        /* For Westwood SND1 audio we need to add the output size and input
           size to the start of the packet to match what is in VQA.
           Specifically, this is needed to signal when a packet should be
           decoding as raw 8-bit pcm or variable-size ADPCM. */
        int out_size = AV_RL16(&preamble[2]);
        if ((ret = av_new_packet(pkt, chunk_size + 4)))
            return ret;
        if ((ret = avio_read(pb, &pkt->data[4], chunk_size)) != chunk_size)
            return ret < 0 ? ret : AVERROR(EIO);
        AV_WL16(&pkt->data[0], out_size);
        AV_WL16(&pkt->data[2], chunk_size);

        pkt->duration = out_size;
    } else {
        ret = av_get_packet(pb, pkt, chunk_size);
        if (ret != chunk_size)
            return AVERROR(EIO);

        /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */
        pkt->duration = (chunk_size * 2) / st->codec->channels;
    }
    pkt->stream_index = st->index;

    return ret;
}
Ejemplo n.º 3
0
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret, size;
    //    AVStream *st = s->streams[0];

    size= MP3_PACKET_SIZE;

    ret= av_get_packet(s->pb, pkt, size);

    pkt->stream_index = 0;
    if (ret <= 0) {
        return AVERROR(EIO);
    }
    /* note: we need to modify the packet size here to handle the last
       packet */
    pkt->size = ret;
    return ret;
}
Ejemplo n.º 4
0
static int tta_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    TTAContext *c = s->priv_data;
    AVStream *st = s->streams[0];
    int size, ret;

    // FIXME!
    if (c->currentframe >= c->totalframes)
        return AVERROR_EOF;

    size = st->index_entries[c->currentframe].size;

    ret = av_get_packet(s->pb, pkt, size);
    pkt->dts = st->index_entries[c->currentframe++].timestamp;
    pkt->duration = c->currentframe == c->totalframes ? c->last_frame_size :
                                                        c->frame_size;
    return ret;
}
Ejemplo n.º 5
0
/**
 * MPEG4 or H264 video frame with a minimal header
 */
static int adbinary_mpeg_minimal(AVFormatContext *s,
                                AVPacket *pkt, int size, int channel,
                                struct NetVuImageData *vidDat, char **text_data,
                                int adDataType)
{
    static const int titleLen  = sizeof(vidDat->title) / sizeof(vidDat->title[0]);
    AdContext*       adContext = s->priv_data;
    AVIOContext *    pb        = s->pb;
    int              dataSize  = size - (4 + 2);
    int              errorVal  = 0;

    // Get the minimal video header and copy into generic video data structure
    memset(vidDat, 0, sizeof(struct NetVuImageData));
    vidDat->session_time  = avio_rb32(pb);
    vidDat->milliseconds  = avio_rb16(pb);

    if ( pb->error || (vidDat->session_time == 0) )  {
        av_log(s, AV_LOG_ERROR, "%s: Reading header, errorcode %d\n",
               __func__, pb->error);
        return ADFFMPEG_AD_ERROR_MPEG4_MINIMAL_GET_BUFFER;
    }
    vidDat->version = PIC_VERSION;
    vidDat->cam = channel + 1;
    vidDat->utc_offset = adContext->utc_offset;
    snprintf(vidDat->title, titleLen, "Camera %d", vidDat->cam);

    // Now get the main frame data into a new packet
    errorVal = av_get_packet(pb, pkt, dataSize);
    if( errorVal < 0 )  {
        av_log(s, AV_LOG_ERROR, "%s: av_get_packet (size %d) failed, status %d\n",
               __func__, dataSize, errorVal);
        return ADFFMPEG_AD_ERROR_MPEG4_MINIMAL_NEW_PACKET;
    }
    
    if (adContext->streamDatatype == 0)  {
        //if (adDataType == AD_DATATYPE_MININAL_H264)
        //    adContext->streamDatatype = PIC_MODE_H264I;
        //else
        adContext->streamDatatype = mpegOrH264(AV_RB32(pkt->data));
    }
    vidDat->vid_format = adContext->streamDatatype;

    return errorVal;
}
Ejemplo n.º 6
0
/**
 * read a single audio or video packet
 * @param s demuxer context
 * @param pkt the packet to be filled
 * @return 0 on success, AVERROR otherwise
 */
static int rl2_read_packet(AVFormatContext *s,
                           AVPacket *pkt)
{
	Rl2DemuxContext *rl2 = s->priv_data;
	AVIOContext *pb = s->pb;
	AVIndexEntry *sample = NULL;
	int i;
	int ret = 0;
	int stream_id = -1;
	int64_t pos = INT64_MAX;

	/** check if there is a valid video or audio entry that can be used */
	for(i=0; i<s->nb_streams; i++)
	{
		if(rl2->index_pos[i] < s->streams[i]->nb_index_entries
		        && s->streams[i]->index_entries[ rl2->index_pos[i] ].pos < pos)
		{
			sample = &s->streams[i]->index_entries[ rl2->index_pos[i] ];
			pos= sample->pos;
			stream_id= i;
		}
	}

	if(stream_id == -1)
		return AVERROR(EIO);

	++rl2->index_pos[stream_id];

	/** position the stream (will probably be there anyway) */
	avio_seek(pb, sample->pos, SEEK_SET);

	/** fill the packet */
	ret = av_get_packet(pb, pkt, sample->size);
	if(ret != sample->size)
	{
		av_free_packet(pkt);
		return AVERROR(EIO);
	}

	pkt->stream_index = stream_id;
	pkt->pts = sample->timestamp;

	return ret;
}
Ejemplo n.º 7
0
static int aiff_read_packet(AVFormatContext *s,
                            AVPacket *pkt)
{
    AVStream *st = s->streams[0];
    int res;

    /* End of stream may be reached */
    if (url_feof(s->pb))
        return AVERROR(EIO);

    /* Now for that packet */
    res = av_get_packet(s->pb, pkt, (MAX_SIZE / st->codec->block_align) * st->codec->block_align);
    if (res < 0)
        return res;

    /* Only one stream in an AIFF file */
    pkt->stream_index = 0;
    return 0;
}
Ejemplo n.º 8
0
static int pmp_packet(AVFormatContext *s, AVPacket *pkt)
{
    PMPContext *pmp = s->priv_data;
    AVIOContext *pb = s->pb;
    int ret = 0;
    int i;

    if (url_feof(pb))
        return AVERROR_EOF;
    if (pmp->cur_stream == 0) {
        int num_packets;
        pmp->audio_packets = avio_r8(pb);
        if (!pmp->audio_packets) {
            avpriv_request_sample(s, "0 audio packets");
            return AVERROR_PATCHWELCOME;
        }
        num_packets = (pmp->num_streams - 1) * pmp->audio_packets + 1;
        avio_skip(pb, 8);
        pmp->current_packet = 0;
        av_fast_malloc(&pmp->packet_sizes,
                       &pmp->packet_sizes_alloc,
                       num_packets * sizeof(*pmp->packet_sizes));
        if (!pmp->packet_sizes_alloc) {
            av_log(s, AV_LOG_ERROR, "Cannot (re)allocate packet buffer\n");
            return AVERROR(ENOMEM);
        }
        for (i = 0; i < num_packets; i++)
            pmp->packet_sizes[i] = avio_rl32(pb);
    }
    ret = av_get_packet(pb, pkt, pmp->packet_sizes[pmp->current_packet]);
    if (ret >= 0) {
        ret = 0;
        // FIXME: this is a hack that should be removed once
        // compute_pkt_fields() can handle timestamps properly
        if (pmp->cur_stream == 0)
            pkt->dts = s->streams[0]->cur_dts++;
        pkt->stream_index = pmp->cur_stream;
    }
    if (pmp->current_packet % pmp->audio_packets == 0)
        pmp->cur_stream = (pmp->cur_stream + 1) % pmp->num_streams;
    pmp->current_packet++;
    return ret;
}
Ejemplo n.º 9
0
static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    AVIOContext *pb = s->pb;
    int ret;
    unsigned int frame_type, packet_size, padding, frame_size;

    avio_rb16(pb);                       /* channel number */
    frame_type  = avio_rb16(pb);
    packet_size = avio_rb32(pb);
    padding     = -packet_size & 511;
    frame_size  = packet_size - 8;

    if (frame_type > LMLM4_MPEG1L2 || frame_type == LMLM4_INVALID)
    {
        av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n");
        return AVERROR(EIO);
    }
    if (packet_size > LMLM4_MAX_PACKET_SIZE)
    {
        av_log(s, AV_LOG_ERROR, "packet size exceeds maximum\n");
        return AVERROR(EIO);
    }

    if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0)
        return AVERROR(EIO);

    avio_skip(pb, padding);

    switch (frame_type)
    {
    case LMLM4_I_FRAME:
        pkt->flags = AV_PKT_FLAG_KEY;
    case LMLM4_P_FRAME:
    case LMLM4_B_FRAME:
        pkt->stream_index = 0;
        break;
    case LMLM4_MPEG1L2:
        pkt->stream_index = 1;
        break;
    }

    return ret;
}
Ejemplo n.º 10
0
static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    AVIOContext *pb = s->pb;
    uint32_t frame_size;
    int ret, first = 1;

    if (pb->eof_reached)
        return AVERROR_EOF;

    if (av_get_packet(pb, pkt, 12) != 12)
        return AVERROR(EIO);
    while (!pb->eof_reached) {
        if (!first) {
            ret = av_append_packet(pb, pkt, 12);
            if (ret < 0) {
                av_free_packet(pkt);
                return ret;
            }
        } else
            first = 0;
        frame_size = AV_RL32(pkt->data + pkt->size - 8);
        if (frame_size > INT_MAX - 4) {
            av_log(s, AV_LOG_ERROR, "Too large chunk size: %"PRIu32"\n", frame_size);
            return AVERROR(EIO);
        }
        if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) {
            if (frame_size) {
                av_log(s, AV_LOG_WARNING,
                       "skipping %"PRIu32" bytes of end-of-frame marker chunk\n",
                       frame_size);
                avio_skip(pb, frame_size);
            }
            return 0;
        }
        ret = av_append_packet(pb, pkt, frame_size);
        if (ret < 0) {
            av_free_packet(pkt);
            return ret;
        }
    }

    return 0;
}
Ejemplo n.º 11
0
static int read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret, count;
    MviDemuxContext *mvi = s->priv_data;
    AVIOContext *pb = s->pb;

    if (mvi->video_frame_size == 0) {
        mvi->video_frame_size = (mvi->get_int)(pb);
        if (mvi->audio_size_left == 0)
            return AVERROR(EIO);
        count = (mvi->audio_size_counter + mvi->audio_frame_size + 512) >> MVI_FRAC_BITS;
        if (count > mvi->audio_size_left)
            count = mvi->audio_size_left;
        if ((ret = av_get_packet(pb, pkt, count)) < 0)
            return ret;
        pkt->stream_index = MVI_AUDIO_STREAM_INDEX;
        mvi->audio_size_left -= count;
        mvi->audio_size_counter += mvi->audio_frame_size - (count << MVI_FRAC_BITS);
    } else {
Ejemplo n.º 12
0
static int read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret;

    while (1) {
        ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
        if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND)
            break;
        av_free_packet(pkt);
    }

    pkt->stream_index = 0;
    pkt->dts=pkt->pts= s->streams[0]->cur_dts;

    if(ret>5 && (pkt->data[0]&0x3F) == 9 && (pkt->data[1]&0x3F)==1 && !(pkt->data[2+2+1] & 0x0F)){
        pkt->flags = AV_PKT_FLAG_KEY;
    }
    return ret;
}
Ejemplo n.º 13
0
static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret;

    ret = av_get_packet(s->pb, pkt, MP3_PACKET_SIZE);
    if (ret < 0)
        return ret;

    pkt->stream_index = 0;

    if (ret > ID3v1_TAG_SIZE &&
        memcmp(&pkt->data[ret - ID3v1_TAG_SIZE], "TAG", 3) == 0)
        ret -= ID3v1_TAG_SIZE;

    /* note: we need to modify the packet size here to handle the last
       packet */
    pkt->size = ret;
    return ret;
}
Ejemplo n.º 14
0
static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
{
    AVStream *st = s->streams[1];
    int tmp, tmp2, samples, size;
    uint64_t pos = url_ftell(s->pb);
    unsigned dts;

    dts = get_be32(s->pb);

    st->codec->sample_rate = get_be32(s->pb);

    samples = get_be32(s->pb);

    tmp = get_be32(s->pb);
    dprintf(s, "packet num %d\n", tmp);

    tmp = get_be16(s->pb); // unkown
    dprintf(s, "unknown %d\n", tmp);

    tmp  = get_byte(s->pb); // major version
    tmp2 = get_byte(s->pb); // minor version
    dprintf(s, "version %d.%d\n", tmp, tmp2);

    tmp = get_be32(s->pb); // unknown
    dprintf(s, "unknown %d\n", tmp);

    size = atom->size - 8 - (url_ftell(s->pb) - pos);
    if (size < 0)
        return -1;
    if (av_get_packet(s->pb, pkt, size) != size) {
        av_log(s, AV_LOG_ERROR, "error reading video packet\n");
        return -1;
    }

    pkt->stream_index = 1;
    pkt->dts = dts;
    pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate);
    dprintf(s, "pkt dts %lld duration %d samples %d sample rate %d\n",
            pkt->dts, pkt->duration, samples, st->codec->sample_rate);

    return 0;
}
Ejemplo n.º 15
0
static int adp_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret, size = 1024;

    if (avio_feof(s->pb))
        return AVERROR_EOF;

    ret = av_get_packet(s->pb, pkt, size);

    if (ret != size) {
        if (ret < 0) {
            av_packet_unref(pkt);
            return ret;
        }
        av_shrink_packet(pkt, ret);
    }
    pkt->stream_index = 0;

    return ret;
}
Ejemplo n.º 16
0
static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret, size;

    size = GSM_BLOCK_SIZE;

    pkt->pos = avio_tell(s->pb);
    pkt->stream_index = 0;

    ret = av_get_packet(s->pb, pkt, size);
    if (ret < GSM_BLOCK_SIZE) {
        av_free_packet(pkt);
        return ret < 0 ? ret : AVERROR(EIO);
    }
    pkt->size     = ret;
    pkt->duration = 1;
    pkt->pts      = pkt->pos / GSM_BLOCK_SIZE;

    return 0;
}
Ejemplo n.º 17
0
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int packet_size, ret, width, height;
    AVStream *st = s->streams[0];

    width = st->codec->width;
    height = st->codec->height;

    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
    if (packet_size < 0)
        return -1;

    ret = av_get_packet(s->pb, pkt, packet_size);
    pkt->pts = pkt->dts = pkt->pos / packet_size;

    pkt->stream_index = 0;
    if (ret < 0)
        return ret;
    return 0;
}
Ejemplo n.º 18
0
static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret, size, bps;
    //    AVStream *st = s->streams[0];

    size= RAW_SAMPLES*s->streams[0]->codec->block_align;

    ret= av_get_packet(s->pb, pkt, size);

    pkt->stream_index = 0;
    if (ret < 0)
        return ret;

    bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
    assert(bps); // if false there IS a bug elsewhere (NOT in this function)
    pkt->dts=
    pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);

    return ret;
}
Ejemplo n.º 19
0
Archivo: cdg.c Proyecto: AVLeo/libav
static int read_packet(AVFormatContext *s, AVPacket *pkt)
{
    CDGContext *priv = s->priv_data;
    int ret;

    while (1) {
        ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
        if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND)
            break;
        av_packet_unref(pkt);
    }

    if (!priv->got_first_packet) {
        pkt->flags |= AV_PKT_FLAG_KEY;
        priv->got_first_packet = 1;
    }

    pkt->stream_index = 0;
    return ret;
}
Ejemplo n.º 20
0
static int pmp_packet(AVFormatContext *s, AVPacket *pkt)
{
    PMPContext *pmp = s->priv_data;
    AVIOContext *pb = s->pb;
    int ret = 0;
    int i;

    if (avio_feof(pb))
        return AVERROR_EOF;
    if (pmp->cur_stream == 0) {
        int num_packets;
        pmp->audio_packets = avio_r8(pb);

        if (!pmp->audio_packets) {
            av_log(s, AV_LOG_ERROR, "No audio packets.\n");
            return AVERROR_INVALIDDATA;
        }

        num_packets = (pmp->num_streams - 1) * pmp->audio_packets + 1;
        avio_skip(pb, 8);
        pmp->current_packet = 0;
        av_fast_malloc(&pmp->packet_sizes,
                       &pmp->packet_sizes_alloc,
                       num_packets * sizeof(*pmp->packet_sizes));
        if (!pmp->packet_sizes_alloc) {
            av_log(s, AV_LOG_ERROR, "Cannot (re)allocate packet buffer\n");
            return AVERROR(ENOMEM);
        }
        for (i = 0; i < num_packets; i++)
            pmp->packet_sizes[i] = avio_rl32(pb);
    }
    ret = av_get_packet(pb, pkt, pmp->packet_sizes[pmp->current_packet]);
    if (ret >= 0) {
        ret = 0;
        pkt->stream_index = pmp->cur_stream;
    }
    if (pmp->current_packet % pmp->audio_packets == 0)
        pmp->cur_stream = (pmp->cur_stream + 1) % pmp->num_streams;
    pmp->current_packet++;
    return ret;
}
Ejemplo n.º 21
0
Archivo: tmv.c Proyecto: AWilco/xbmc
static int tmv_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    TMVContext *tmv   = s->priv_data;
    ByteIOContext *pb = s->pb;
    int ret, pkt_size = tmv->stream_index ?
                        tmv->audio_chunk_size : tmv->video_chunk_size;

    if (url_feof(pb))
        return AVERROR_EOF;

    ret = av_get_packet(pb, pkt, pkt_size);

    if (tmv->stream_index)
        url_fskip(pb, tmv->padding);

    pkt->stream_index  = tmv->stream_index;
    tmv->stream_index ^= 1;
    pkt->flags        |= AV_PKT_FLAG_KEY;

    return ret;
}
Ejemplo n.º 22
0
Archivo: iff.c Proyecto: AVLeo/libav
static int iff_read_packet(AVFormatContext *s,
                           AVPacket *pkt)
{
    IffDemuxContext *iff = s->priv_data;
    AVIOContext *pb = s->pb;
    int ret;

    if(iff->sent_bytes >= iff->body_size)
        return AVERROR_EOF;

    ret = av_get_packet(pb, pkt, iff->body_size);
    if (ret < 0)
        return ret;

    if(iff->sent_bytes == 0)
        pkt->flags |= AV_PKT_FLAG_KEY;
    iff->sent_bytes = iff->body_size;

    pkt->stream_index = 0;
    return ret;
}
Ejemplo n.º 23
0
/**
 * Audio frame with a Netvu header
 */
static int ad_read_audio(AVFormatContext *s,
                         AVPacket *pkt, int size, 
                         struct NetVuAudioData *data,
                         enum AVCodecID codec_id)
{
    AVIOContext *pb = s->pb;
    int status;

    // Get the fixed size portion of the audio header
    size = NetVuAudioDataHeaderSize - sizeof(unsigned char *);
    if (avio_read( pb, (uint8_t*)data, size) != size)
        return ADFFMPEG_AD_ERROR_AUDIO_ADPCM_GET_BUFFER;

    // endian fix it...
    audioheader_network2host(data, (uint8_t*)data);

    // Now get the additional bytes
    if( data->sizeOfAdditionalData > 0 ) {
        data->additionalData = av_malloc( data->sizeOfAdditionalData );
        if( data->additionalData == NULL )
            return AVERROR(ENOMEM);

        if (avio_read( pb, data->additionalData, data->sizeOfAdditionalData) != data->sizeOfAdditionalData)
            return ADFFMPEG_AD_ERROR_AUDIO_ADPCM_GET_BUFFER2;
    }
    else
        data->additionalData = NULL;

    status = av_get_packet(pb, pkt, data->sizeOfAudioData);
    if (status  < 0)  {
        av_log(s, AV_LOG_ERROR, "%s: av_get_packet (size %d) failed, status %d\n",
               __func__, data->sizeOfAudioData, status);
        return ADFFMPEG_AD_ERROR_AUDIO_ADPCM_MIME_NEW_PACKET;
    }
    
    if (codec_id == CODEC_ID_ADPCM_IMA_WAV)
        audiodata_network2host(pkt->data, pkt->data, data->sizeOfAudioData);

    return status;
}
Ejemplo n.º 24
0
static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int i;
    char header[MAX_FRAME_HEADER+1];
    int packet_size, width, height, ret;
    AVStream *st = s->streams[0];

    for (i = 0; i < MAX_FRAME_HEADER; i++) {
        header[i] = avio_r8(s->pb);
        if (header[i] == '\n') {
            header[i + 1] = 0;
            break;
        }
    }
    if (s->pb->error)
        return s->pb->error;
    else if (s->pb->eof_reached)
        return AVERROR_EOF;
    else if (i == MAX_FRAME_HEADER)
        return AVERROR_INVALIDDATA;

    if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC)))
        return AVERROR_INVALIDDATA;

    width  = st->codec->width;
    height = st->codec->height;

    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
    if (packet_size < 0)
        return packet_size;

    ret = av_get_packet(s->pb, pkt, packet_size);
    if (ret < 0)
        return ret;
    else if (ret != packet_size)
        return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO);

    pkt->stream_index = 0;
    return 0;
}
Ejemplo n.º 25
0
static int wav_read_packet(AVFormatContext *s,
                           AVPacket *pkt)
{
    int ret, size;
    int64_t left;
    AVStream *st;
    WAVContext *wav = s->priv_data;

    if (url_feof(s->pb))
        return AVERROR(EIO);
    st = s->streams[0];

    left = wav->data_end - url_ftell(s->pb);
    if (left <= 0){
        if (CONFIG_W64_DEMUXER && wav->w64)
            left = find_guid(s->pb, guid_data) - 24;
        else
            left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));
        if (left < 0)
            return AVERROR(EIO);
        wav->data_end= url_ftell(s->pb) + left;
    }

    size = MAX_SIZE;
    if (st->codec->block_align > 1) {
        if (size < st->codec->block_align)
            size = st->codec->block_align;
        size = (size / st->codec->block_align) * st->codec->block_align;
    }
    size = FFMIN(size, left);
    ret  = av_get_packet(s->pb, pkt, size);
    if (ret <= 0)
        return AVERROR(EIO);
    pkt->stream_index = 0;

    /* note: we need to modify the packet size here to handle the last
       packet */
    pkt->size = ret;
    return ret;
}
Ejemplo n.º 26
0
static int lvf_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    unsigned size, flags, timestamp, id;
    int64_t pos;
    int ret, is_video = 0;

    pos = avio_tell(s->pb);
    while (!url_feof(s->pb)) {
        id    = avio_rl32(s->pb);
        size  = avio_rl32(s->pb);

        if (size == 0xFFFFFFFFu)
            return AVERROR_EOF;

        switch (id) {
        case MKTAG('0', '0', 'd', 'c'):
            is_video = 1;
        case MKTAG('0', '1', 'w', 'b'):
            if (size < 8)
                return AVERROR_INVALIDDATA;
            timestamp = avio_rl32(s->pb);
            flags = avio_rl32(s->pb);
            ret = av_get_packet(s->pb, pkt, size - 8);
            if (flags & (1 << 12))
                pkt->flags |= AV_PKT_FLAG_KEY;
            pkt->stream_index = is_video ? 0 : 1;
            pkt->pts          = timestamp;
            pkt->pos          = pos;
            return ret;
        default:
            ret = avio_skip(s->pb, size);
        }

        if (ret < 0)
            return ret;
    }

    return AVERROR_EOF;
}
Ejemplo n.º 27
0
static int redspark_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    AVCodecParameters *par = s->streams[0]->codecpar;
    RedSparkContext *redspark = s->priv_data;
    uint32_t size = 8 * par->channels;
    int ret;

    if (avio_feof(s->pb) || redspark->samples_count == s->streams[0]->duration)
        return AVERROR_EOF;

    ret = av_get_packet(s->pb, pkt, size);
    if (ret != size) {
        av_packet_unref(pkt);
        return AVERROR(EIO);
    }

    pkt->duration = 14;
    redspark->samples_count += pkt->duration;
    pkt->stream_index = 0;

    return ret;
}
Ejemplo n.º 28
0
static int sdr2_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int64_t pos;
    unsigned next;
    int flags, ret = 0, is_video;

    pos = avio_tell(s->pb);

    flags = avio_rl32(s->pb);
    avio_skip(s->pb, 4);

    next = avio_rl32(s->pb);
    if (next <= 52)
        return AVERROR_INVALIDDATA;

    avio_skip(s->pb, 6);
    is_video = avio_rl32(s->pb);
    avio_skip(s->pb, 30);

    if (pos == FIRST) {
        if (av_new_packet(pkt, next - 52 + 24) < 0)
            return AVERROR(ENOMEM);
        memcpy(pkt->data, header, 24);
        ret = avio_read(s->pb, pkt->data + 24, next - 52);
        if (ret < 0) {
            av_free_packet(pkt);
            return ret;
        }
        av_shrink_packet(pkt, ret + 24);
    } else {
        ret = av_get_packet(s->pb, pkt, next - 52);
    }
    pkt->stream_index = !!is_video;
    pkt->pos = pos;
    if (flags & (1 << 12))
        pkt->flags |= AV_PKT_FLAG_KEY;

    return ret;
}
Ejemplo n.º 29
0
static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
{
    TtyDemuxContext *s = avctx->priv_data;
    int n;

    if (url_feof(avctx->pb))
        return AVERROR_EOF;

    n = s->chars_per_frame;
    if (s->fsize) {
        // ignore metadata buffer
        uint64_t p = url_ftell(avctx->pb);
        if (p + s->chars_per_frame > s->fsize)
            n = s->fsize - p;
    }

    pkt->size = av_get_packet(avctx->pb, pkt, n);
    if (pkt->size <= 0)
        return AVERROR(EIO);
    pkt->flags |= AV_PKT_FLAG_KEY;
    return 0;
}
Ejemplo n.º 30
0
Archivo: txd.c Proyecto: Arcen/FFmpeg
static int txd_read_packet(AVFormatContext *s, AVPacket *pkt) {
    AVIOContext *pb = s->pb;
    unsigned int id, chunk_size, marker;
    int ret;

next_chunk:
    id         = avio_rl32(pb);
    chunk_size = avio_rl32(pb);
    marker     = avio_rl32(pb);

    if (url_feof(s->pb))
        return AVERROR_EOF;
    if (marker != TXD_MARKER && marker != TXD_MARKER2) {
        av_log(s, AV_LOG_ERROR, "marker does not match\n");
        return AVERROR_INVALIDDATA;
    }

    switch (id) {
        case TXD_INFO:
            if (chunk_size > 100)
                break;
        case TXD_EXTRA:
            avio_skip(s->pb, chunk_size);
        case TXD_FILE:
        case TXD_TEXTURE:
            goto next_chunk;
        default:
            av_log(s, AV_LOG_ERROR, "unknown chunk id %i\n", id);
            return AVERROR_INVALIDDATA;
    }

    ret = av_get_packet(s->pb, pkt, chunk_size);
    if (ret < 0)
        return ret;
    pkt->stream_index = 0;

    return 0;
}