Beispiel #1
0
/**
 * Audio frame with a minimal header
 */
static int adbinary_audio_minimal(AVFormatContext *s,
                                  AVPacket *pkt, int size, 
                                  struct NetVuAudioData *data)
{
    AVIOContext *pb = s->pb;
    int dataSize = size - (4 + 2 + 2);
    int status;

    // Get the minimal audio header and copy into generic audio data structure
    memset(data, 0, sizeof(struct NetVuAudioData));
    data->seconds = avio_rb32(pb);
    data->msecs   = avio_rb16(pb);
    data->mode    = avio_rb16(pb);
    if ( pb->error || (data->seconds == 0) )  {
        av_log(s, AV_LOG_ERROR, "%s: Reading header, errorcode %d\n",
               __func__, pb->error);
        return ADFFMPEG_AD_ERROR_MINIMAL_AUDIO_ADPCM_GET_BUFFER;
    }

    // Now get the main frame data into a new packet
    status = av_get_packet(pb, pkt, dataSize);
    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_MINIMAL_AUDIO_ADPCM_NEW_PACKET;
    }

    audiodata_network2host(pkt->data, pkt->data, dataSize);

    return status;
}
Beispiel #2
0
static int adaudio_read_packet(struct AVFormatContext *s, AVPacket *pkt)
{
    AVIOContext *         ioContext = s->pb;
    int                   retVal = AVERROR(EIO);
    int                   packetSize = 0;
    int                   sampleSize = 0;
    AVStream *            st = NULL;
    int                   isPacketAlloced = 0;
#ifdef AD_SIDEDATA_IN_PRIV
    struct ADFrameData *    frameData = NULL;
#endif

    /* Get the next packet */
    if( (packetSize = ioContext->read_packet( ioContext->opaque, ioContext->buf_ptr, ioContext->buffer_size )) > 0 ) {
        /* Validate the 12 byte RTP header as best we can */
        if( ioContext->buf_ptr[1] == RTP_PAYLOAD_TYPE_8000HZ_ADPCM ||
            ioContext->buf_ptr[1] == RTP_PAYLOAD_TYPE_11025HZ_ADPCM ||
            ioContext->buf_ptr[1] == RTP_PAYLOAD_TYPE_16000HZ_ADPCM ||
            ioContext->buf_ptr[1] == RTP_PAYLOAD_TYPE_22050HZ_ADPCM
          ) {
            /* Calculate the size of the sample data */
            sampleSize = packetSize - SIZEOF_RTP_HEADER;

            /* Create a new AVPacket */
            if( av_new_packet( pkt, sampleSize ) >= 0 ) {
                isPacketAlloced = 1;

                /* Copy data into packet */
                audiodata_network2host(pkt->data, &ioContext->buf_ptr[SIZEOF_RTP_HEADER], sampleSize);

                /* Configure stream info */
                if( (st = ad_get_audio_stream(s, NULL)) != NULL ) {
                    pkt->stream_index = st->index;
                    pkt->duration =  ((int)(AV_TIME_BASE * 1.0));

#ifdef AD_SIDEDATA_IN_PRIV
                    if( (frameData = av_malloc(sizeof(*frameData))) != NULL )  {
                        /* Set the frame info up */
                        frameData->frameType = RTPAudio;
                        frameData->frameData = (void*)(&ioContext->buf_ptr[1]);
                        frameData->additionalData = NULL;

                        pkt->priv = (void*)frameData;
                        retVal = 0;
                    }
                    else
                        retVal = AVERROR(ENOMEM);
#endif
                }
            }
        }
    }

    /* Check whether we need to release the packet data we allocated */
    if( retVal < 0 && isPacketAlloced != 0 ) {
        av_free_packet( pkt );
    }

    return retVal;
}
Beispiel #3
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;
}