Esempio n. 1
0
/*
 * Process PT/GSTR sound header
 * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx
 */
static int process_audio_header_elements(AVFormatContext *s)
{
    int inHeader = 1;
    EaDemuxContext *ea = s->priv_data;
    ByteIOContext *pb = s->pb;
    int compression_type = -1, revision = -1, revision2 = -1;

    ea->bytes = 2;
    ea->sample_rate = -1;
    ea->num_channels = 1;

    while (inHeader) {
        int inSubheader;
        uint8_t byte;
        byte = get_byte(pb);

        switch (byte) {
        case 0xFD:
            av_log (s, AV_LOG_DEBUG, "entered audio subheader\n");
            inSubheader = 1;
            while (inSubheader) {
                uint8_t subbyte;
                subbyte = get_byte(pb);

                switch (subbyte) {
                case 0x80:
                    revision = read_arbitary(pb);
                    av_log (s, AV_LOG_DEBUG, "revision (element 0x80) set to 0x%08x\n", revision);
                    break;
                case 0x82:
                    ea->num_channels = read_arbitary(pb);
                    av_log (s, AV_LOG_DEBUG, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
                    break;
                case 0x83:
                    compression_type = read_arbitary(pb);
                    av_log (s, AV_LOG_DEBUG, "compression_type (element 0x83) set to 0x%08x\n", compression_type);
                    break;
                case 0x84:
                    ea->sample_rate = read_arbitary(pb);
                    av_log (s, AV_LOG_DEBUG, "sample_rate (element 0x84) set to %i\n", ea->sample_rate);
                    break;
                case 0x85:
                    ea->num_samples = read_arbitary(pb);
                    av_log (s, AV_LOG_DEBUG, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
                    break;
                case 0x8A:
                    av_log (s, AV_LOG_DEBUG, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
                    av_log (s, AV_LOG_DEBUG, "exited audio subheader\n");
                    inSubheader = 0;
                    break;
                case 0xA0:
                    revision2 = read_arbitary(pb);
                    av_log (s, AV_LOG_DEBUG, "revision2 (element 0xA0) set to 0x%08x\n", revision2);
                    break;
                case 0xFF:
                    av_log (s, AV_LOG_DEBUG, "end of header block reached (within audio subheader)\n");
                    inSubheader = 0;
                    inHeader = 0;
                    break;
                default:
                    av_log (s, AV_LOG_DEBUG, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
                    break;
                }
            }
            break;
        case 0xFF:
            av_log (s, AV_LOG_DEBUG, "end of header block reached\n");
            inHeader = 0;
            break;
        default:
            av_log (s, AV_LOG_DEBUG, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
            break;
        }
    }

    switch (compression_type) {
    case  0: ea->audio_codec = CODEC_ID_PCM_S16LE; break;
    case  7: ea->audio_codec = CODEC_ID_ADPCM_EA; break;
    case -1:
        switch (revision) {
        case  1: ea->audio_codec = CODEC_ID_ADPCM_EA_R1; break;
        case  2: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break;
        case  3: ea->audio_codec = CODEC_ID_ADPCM_EA_R3; break;
        case -1: break;
        default:
            av_log(s, AV_LOG_ERROR, "unsupported stream type; revision=%i\n", revision);
            return 0;
        }
        switch (revision2) {
        case  8: ea->audio_codec = CODEC_ID_PCM_S16LE_PLANAR; break;
        case 10: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break;
        case 16: ea->audio_codec = CODEC_ID_MP3; break;
        case -1: break;
        default:
            ea->audio_codec = CODEC_ID_NONE;
            av_log(s, AV_LOG_ERROR, "unsupported stream type; revision2=%i\n", revision2);
            return 0;
        }
        break;
    default:
        av_log(s, AV_LOG_ERROR, "unsupported stream type; compression_type=%i\n", compression_type);
        return 0;
    }

    if (ea->sample_rate == -1)
        ea->sample_rate = revision==3 ? 48000 : 22050;

    return 1;
}
Esempio n. 2
0
/*
 * Process WVE file header
 * Returns 1 if the WVE file is valid and successfully opened, 0 otherwise
 */
static int process_ea_header(AVFormatContext *s) {
    int inHeader;
    uint32_t blockid, size;
    EaDemuxContext *ea = s->priv_data;
    ByteIOContext *pb = &s->pb;

    if (get_buffer(pb, (void*)&blockid, 4) != 4) {
        return 0;
    }
    if (le2me_32(blockid) != SCHl_TAG) {
        return 0;
    }

    if (get_buffer(pb, (void*)&size, 4) != 4) {
        return 0;
    }
    size = le2me_32(size);

    if (get_buffer(pb, (void*)&blockid, 4) != 4) {
        return 0;
    }
    if (le2me_32(blockid) != PT00_TAG) {
        av_log (s, AV_LOG_ERROR, "PT header missing\n");
        return 0;
    }

    inHeader = 1;
    while (inHeader) {
        int inSubheader;
        uint8_t byte;
        byte = get_byte(pb) & 0xFF;

        switch (byte) {
        case 0xFD:
            av_log (s, AV_LOG_INFO, "entered audio subheader\n");
            inSubheader = 1;
            while (inSubheader) {
                uint8_t subbyte;
                subbyte = get_byte(pb) & 0xFF;

                switch (subbyte) {
                case 0x82:
                    ea->num_channels = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
                    break;
                case 0x83:
                    ea->compression_type = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", ea->compression_type);
                    break;
                case 0x85:
                    ea->num_samples = read_arbitary(pb);
                    av_log (s, AV_LOG_INFO, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
                    break;
                case 0x8A:
                    av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
                    av_log (s, AV_LOG_INFO, "exited audio subheader\n");
                    inSubheader = 0;
                    break;
                default:
                    av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
                    break;
                }
            }
            break;
        case 0xFF:
            av_log (s, AV_LOG_INFO, "end of header block reached\n");
            inHeader = 0;
            break;
        default:
            av_log (s, AV_LOG_INFO, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
            break;
        }
    }

    if ((ea->num_channels != 2) || (ea->compression_type != 7)) {
        av_log (s, AV_LOG_ERROR, "unsupported stream type\n");
        return 0;
    }

    /* skip to the start of the data */
    url_fseek(pb, size, SEEK_SET);

    return 1;
}