Menu

insertData never gets called on my TheoraAudioInterface

2014-09-04
2014-09-05
  • Ariel Manzur

    Ariel Manzur - 2014-09-04

    (sorry for the repost on the issue tracker, I thought the website was down and I could only find the google code page, turns out it just doesn't work on my browser :p )

    Hi.

    I'm in the process of integrating libtheoraplayer on our engine (Godot Engine, MIT license, source here https://github.com/okamstudio/godot), the problem I'm having is that I'm providing my own TheoraAudioInterface, and it gets instanced, but insertData never gets called. What's the best way to diagnose the problem? As far as I know my video has Vorbis sound and I can hear it with VLC. What's a good tool to tell exactly what codecs I'm using?

    I'm using -D_YUV_C and -D__THEORA for the preprocessor (with -D__AVFOUNDATION for ios and -D_ANDROID for android).

    For reference, here's the code I'm using:


    class TPAudioGodot : public TheoraAudioInterface {

    Ref<AudioStreamInput> stream;
    

    public:

    void insertData(float* data, int nSamples) {
    
        stream->input(data, nSamples);
    };
    
    TPAudioGodot(TheoraVideoClip* owner, int nChannels, int freq)
        : TheoraAudioInterface(owner, nChannels, freq) {
    
        printf("***************** audio interface constructor\n");
        stream = Ref<AudioStreamInput>(memnew(AudioStreamInput(nChannels, freq)));
    };
    

    };

    class TPAudioGodotFactory : public TheoraAudioInterfaceFactory {

    public:
    TheoraAudioInterface createInstance(TheoraVideoClip owner, int nChannels, int freq) {

        printf("************** creating audio output\n");
        return memnew(TPAudioGodot(owner, nChannels, freq));
    };
    

    };

    int VideoStreamTheoraplayer::get_pending_frame_count() const {

    if (!clip)
        return 0;
    
    if (!frame.empty())
        return 1;
    
    TheoraVideoFrame* f = clip->getNextFrame();
    if (!f)
        return 0;
    
    float w=clip->getWidth(),h=clip->getHeight();
    
    int size = f->getStride() * f->getHeight() * f->mBpp;
    
    DVector<uint8_t> data;
    data.resize(size);
    DVector<uint8_t>::Write wr = data.write();
    copymem(wr.ptr(), f->getBuffer(), size);
    
    frame = Image();
    frame.create(w, h, 0, Image::FORMAT_RGB, data);
    
    clip->popFrame();
    
    return 1;
    

    };

    void VideoStreamTheoraplayer::update(float p_time) {

    if (!mgr)
        return;
    
    if (started) {
        if (clip->getNumReadyFrames() < 2) {
            return;
        };
        started = false;
        clip->play();
    } else if (clip->isDone()) {
        playing = false;
    };
    
    clip->update(p_time);
    

    };

    static TPAudioGodotFactory* audio_factory = NULL;

    void VideoStreamTheoraplayer::set_file(const String& p_file) {

    if (!audio_factory) {
        audio_factory = memnew(TPAudioGodotFactory);
    };
    
    mgr = memnew(TheoraVideoManager);
    mgr->setAudioInterfaceFactory(audio_factory);
    
    TheoraDataSource* ds = memnew(TPDataFA(p_file));
    clip = mgr->createVideoClip(ds);
    started = true;
    

    };

    [...]

    Thanks!

    Ariel.

     

Log in to post a comment.

MongoDB Logo MongoDB