Newer
Older
Import / research / pipeline / Modules / MP3SourceModule.cpp
@John Ryland John Ryland on 22 Dec 2020 982 bytes add new projects


class MP3SourceModule : public SimpleModule {
public:
    MP3SourceModule() : avFormatContext( 0 )
    {
    }

    void init()
    {
	av_register_all();
    }
    
    void process( const Frame &frame ) {
        printf("file: %s\n", (char*)frame.data());
        if ( av_open_input_file(&avFormatContext, (char*)frame.data(), NULL, 0, 0) < 0 || !avFormatContext )
            printf("error opening file"); 
    
        while( avFormatContext ) {
            if ( av_read_packet(avFormatContext, &pkt) < 0 )
                printf("error reading packet\n");
            else {
                SimpleModule::process( Frame( "FRAME_ID_MPEG_AUDIO_PACKET", &pkt ) );
            }
        }
    }

    const char *name() { return "MP3 Reader"; }
    Format inputFormat() { return "FRAME_ID_URL_SOURCE"; }
    Format outputFormat() { return "FRAME_ID_MPEG_AUDIO_PACKET"; }
    bool isBlocking() { return true; }

private:
    AVPacket pkt;
    AVFormatContext *avFormatContext;
};