# HG changeset patch # User Matti Hamalainen # Date 1375821905 -10800 # Node ID 9c63b355c82b6b33ceb9854d8f3554ecd4687ff4 # Parent 3eacedd172ab21d9c6449c1de5659b0d4e851124 Remove the audio code completely. diff -r 3eacedd172ab -r 9c63b355c82b liboggplayer-src/src/imp.hpp --- a/liboggplayer-src/src/imp.hpp Tue Aug 06 23:27:37 2013 +0300 +++ b/liboggplayer-src/src/imp.hpp Tue Aug 06 23:45:05 2013 +0300 @@ -1,13 +1,7 @@ #include -#ifdef VORBIS_SUPPORT -#include "SDL_audiocvt.hpp" -#endif #include #include #include -#ifdef VORBIS_SUPPORT -#include -#endif #include #include #include @@ -19,7 +13,7 @@ struct OggPlayer::Imp { Imp() : - cirbuf(0),video_lock(video_mut, boost::defer_lock){ + video_lock(video_mut, boost::defer_lock){ failbit = false; playing = false; need_close = false; @@ -40,9 +34,6 @@ bool parse_headers(); void open(std::string path, AudioFormat audio_format, int channels, int rate, VideoFormat video_format); -#ifdef VORBIS_SUPPORT - bool decode_audio(); -#endif bool decode_video(); bool ready(); void play(); @@ -56,11 +47,6 @@ ogg_sync_state o_sync; -#ifdef VORBIS_SUPPORT - vorbis_comment v_comment; - vorbis_info v_info; -#endif - theora_info t_info; theora_comment t_comment; @@ -72,37 +58,19 @@ theora_state t_state; -#ifdef VORBIS_SUPPORT - vorbis_dsp_state v_state; - vorbis_block v_block; -#endif - int pp_level_max; int pp_level; int pp_inc; - char* audio_buffer; - boost::circular_buffer cirbuf; - unsigned int audio_buffer_size; -#ifdef VORBIS_SUPPORT - SDL_AudioCVT cvt; -#endif - bool playing; boost::thread play_thread; boost::mutex video_mut; boost::condition_variable video_ready_cond; -#ifdef VORBIS_SUPPORT - boost::mutex audio_mut; - boost::condition_variable audio_ready_cond; -#endif bool videobuf_ready; double videobuf_time; - bool audio_cache_ready; - // This lock should only be used from the main thread boost::unique_lock video_lock; // These variables are used to identify the frames (not just count them, not a debug variable) @@ -110,12 +78,6 @@ int frame; int last_frame_read; - int audio_bytes_played; - struct AudioGranulePos { - int pos; - double set_time; - }; - std::deque audio_granule_poses; double time_factor; struct PixelFormat{ diff -r 3eacedd172ab -r 9c63b355c82b liboggplayer-src/src/oggplayer.cpp --- a/liboggplayer-src/src/oggplayer.cpp Tue Aug 06 23:27:37 2013 +0300 +++ b/liboggplayer-src/src/oggplayer.cpp Tue Aug 06 23:45:05 2013 +0300 @@ -60,31 +60,6 @@ return imp->playing; } - -#ifdef VORBIS_SUPPORT -int OggPlayer::audio_read(char* buf, unsigned int size) { - if(NULL==buf || !imp->vorbis_p || !playing() || !imp->ready()) return 0; - boost::unique_lock lock(imp->audio_mut); - - while ((imp->cirbuf.size() < size) && playing()) { - if(imp->cirbuf.capacity()< size) - { - imp->cirbuf.set_capacity(2*size); - } - imp->audio_ready_cond.wait(lock); - } - - unsigned int k = 0; - while (k < size && !imp->cirbuf.empty()) { - buf[k++] = imp->cirbuf.front(); - imp->cirbuf.pop_front(); - } - imp->audio_bytes_played+=k; - - return k; -} -#endif - bool OggPlayer::yuv_buffer_try_lock(YUVBuffer *buffer) { if (!playing() || !imp->theora_p || !imp->ready()) return false; diff -r 3eacedd172ab -r 9c63b355c82b liboggplayer-src/src/open_close.cpp --- a/liboggplayer-src/src/open_close.cpp Tue Aug 06 23:27:37 2013 +0300 +++ b/liboggplayer-src/src/open_close.cpp Tue Aug 06 23:45:05 2013 +0300 @@ -3,16 +3,6 @@ void OggPlayer::Imp::close() { if(!need_close) return; -#ifdef VORBIS_SUPPORT - if (vorbis_p) { - ogg_stream_clear(&o_vsstate); - vorbis_block_clear(&v_block); - vorbis_dsp_clear(&v_state); - } - vorbis_comment_clear(&v_comment); - vorbis_info_clear(&v_info); -#endif - if (theora_p) { ogg_stream_clear(&o_tsstate); theora_clear(&t_state); @@ -22,10 +12,6 @@ ogg_sync_clear(&o_sync); file_in.close(); - if (audio_buffer){ - delete[] audio_buffer; - audio_buffer = NULL; - } need_close = false; } bool OggPlayer::Imp::parse_headers() { @@ -55,14 +41,6 @@ memcpy(&o_tsstate, &test, sizeof(test)); theora_p = 1; } else -#ifdef VORBIS_SUPPORT - if (!vorbis_p && vorbis_synthesis_headerin(&v_info, - &v_comment, &o_packet) >= 0) { - /* it is vorbis */ - memcpy(&o_vsstate, &test, sizeof(test)); - vorbis_p = 1; - } else -#endif { /* whatever it is, we don't care about it */ ogg_stream_clear(&test); @@ -72,9 +50,6 @@ // we're expecting more header packets. while ((theora_p && theora_p < 3) -#ifdef VORBIS_SUPPORT - || (vorbis_p && vorbis_p < 3) -#endif ) { int ret; @@ -92,24 +67,6 @@ theora_p++; } -#ifdef VORBIS_SUPPORT - // look for more vorbis header packets - while (vorbis_p && (vorbis_p < 3) && (ret = ogg_stream_packetout( - &o_vsstate, &o_packet))) { - if (ret < 0) { - fprintf(stderr, "X: 2\n"); - return false; - } - if (vorbis_synthesis_headerin(&v_info, &v_comment, &o_packet)) { - fprintf(stderr, "X: 3\n"); - return false; - } - vorbis_p++; - if (vorbis_p == 3) - break; - } -#endif - // The header pages/packets will arrive before anything else we // care about, or the stream is not obeying spec @@ -139,15 +96,6 @@ fprintf(stderr, "DDD: 0\n"); return false; } -#ifdef VORBIS_SUPPORT - if (vorbis_p) { - vorbis_synthesis_init(&v_state, &v_info); - vorbis_block_init(&v_state, &v_block); - } else { - fprintf(stderr, "DDD: 1\n"); - return false; - } -#endif return true; } @@ -170,10 +118,6 @@ // 2) init some structs ogg_sync_init(&o_sync); -#ifdef VORBIS_SUPPORT - vorbis_info_init(&v_info); - vorbis_comment_init(&v_comment); -#endif theora_info_init(&t_info); theora_comment_init(&t_comment); @@ -193,30 +137,12 @@ if (failbit) { theora_info_clear(&t_info); theora_comment_clear(&t_comment); -#ifdef VORBIS_SUPPORT - vorbis_info_clear(&v_info); - vorbis_comment_clear(&v_comment); -#endif ogg_sync_clear(&o_sync); file_in.close(); fprintf(stderr, "XXX: done\n"); return; } -#ifdef VORBIS_SUPPORT - // 5) init audio conversion - int ret = SDL_BuildAudioCVT(&cvt, AUDIO_S16, v_info.channels, - v_info.rate, audio_format, channels, rate); - if (-1 == ret) { - failbit = true; - return; - } -#endif - - // play() will allocate memory when needed - audio_buffer_size = 0; - audio_buffer = NULL; - switch(video_format){ //pixel_format.set(r_offset,g_offset,b_offset,bpp not a_offset); case VF_RGB: diff -r 3eacedd172ab -r 9c63b355c82b liboggplayer-src/src/play.cpp --- a/liboggplayer-src/src/play.cpp Tue Aug 06 23:27:37 2013 +0300 +++ b/liboggplayer-src/src/play.cpp Tue Aug 06 23:45:05 2013 +0300 @@ -1,95 +1,8 @@ #include "imp.hpp" bool OggPlayer::Imp::ready() { -#ifdef VORBIS_SUPPORT - return audio_cache_ready; -#else - return true; -#endif -} - - -#ifdef VORBIS_SUPPORT -// return true if need more data -// the return value is strange but the function is -// for internal use only and should only be called -// in play() -bool OggPlayer::Imp::decode_audio() { - int ret; - float **pcm; - // if there's pending, decoded audio, grab it - while ((ret = vorbis_synthesis_pcmout(&v_state, &pcm)) > 0) { - boost::unique_lock lock(audio_mut); - // first we need to convert from float to signed short - // then we will use SDL_ConvertAudio - // is our temp buffer big enough? - if (cirbuf.capacity() < ret * v_info.channels * cvt.len_mult - * sizeof(short)) { - cirbuf.set_capacity(ret * v_info.channels * cvt.len_mult * 16 - * sizeof(short)); - } - if (cirbuf.capacity() - cirbuf.size() < ret * v_info.channels - * cvt.len_mult * sizeof(short)) { - audio_cache_ready = true; - return false; - } - if ((audio_buffer_size) < ret * v_info.channels * cvt.len_mult - * sizeof(short)) { - if (audio_buffer) - delete[] audio_buffer; - audio_buffer_size = ret * v_info.channels * cvt.len_mult - * sizeof(short); - audio_buffer = new char[audio_buffer_size]; - } - // convert from float to short - int k = 0; - char* char_ab = (char*) audio_buffer; - short* short_ab = (short*) audio_buffer; - for (int i = 0; i < ret; i++) { - for (int j = 0; j < v_info.channels; j++) { - int val = (int)(pcm[j][i] * 32767.f); - if (val > 32767) - val = 32767; - if (val < -32768) - val = -32768; - short_ab[k++] = val; - - } - } - vorbis_synthesis_read(&v_state, ret); - // now we can use SDL_ConvertAudio - cvt.len = k * sizeof(short); - cvt.buf = (Uint8*) char_ab; - SDL_ConvertAudio(&cvt); - - for (int i = 0; i < cvt.len_cvt; i++) { - cirbuf.push_back(char_ab[i]); - } - - - if(v_state.granulepos!=0){ - AudioGranulePos agp; - agp.pos = audio_bytes_played+cvt.len_cvt; - agp.set_time = (double)v_state.granulepos/(double)v_info.rate; - audio_granule_poses.push_back(agp); - } - - lock.unlock(); - audio_ready_cond.notify_one(); - return false; - - } - // no pending audio; is there a pending packet to decode? - if (ogg_stream_packetout(&o_vsstate, &o_packet) > 0) { - if (vorbis_synthesis(&v_block, &o_packet) == 0) { - vorbis_synthesis_blockin(&v_state, &v_block); - return false; - } - } else { return true; } return true; } -#endif - // similar to decode_audio bool OggPlayer::Imp::decode_video() { bool was_ready=videobuf_ready; @@ -138,56 +51,31 @@ void OggPlayer::Imp::play_loop() { if(!file_in.is_open()) return; -#ifdef VORBIS_SUPPORT - audio_cache_ready = false; - audio_bytes_played = 0; - bool audio_need_data = vorbis_p; -#else - bool audio_need_data = false; -#endif bool video_need_data = theora_p; timer.restart(); // buffer_data() will close the file on eof - while ((file_in.is_open() || !audio_need_data || !video_need_data) && playing) { - - // sync audio video timer - while(!audio_granule_poses.empty() && - audio_granule_poses.front().pos <= audio_bytes_played){ - time_factor= audio_granule_poses.front().set_time/timer.elapsed(); - audio_granule_poses.pop_front(); - } - + while ((file_in.is_open() || !video_need_data) && playing) { if (theora_p && !videobuf_ready) { video_need_data = decode_video(); } -#ifdef VORBIS_SUPPORT - if (vorbis_p) { - audio_need_data = decode_audio(); - } -#endif - // are we at or past time for this video frame? if (videobuf_ready && videobuf_time <= get_time()) { videobuf_ready = false; } // if no data yet for somebody, grab another page - if (file_in.is_open() && (audio_need_data || video_need_data)) { + if (file_in.is_open() && (video_need_data)) { // buffer_data() can handle eof itself buffer_data(); while (ogg_sync_pageout(&o_sync, &o_page) > 0) { queue_page(&o_page); } - audio_need_data = false; video_need_data = false; } } playing = false; // do not risk a lock -#ifdef VORBIS_SUPPORT - audio_ready_cond.notify_one(); -#endif video_ready_cond.notify_one(); // cleanup diff -r 3eacedd172ab -r 9c63b355c82b liboggplayer-src/src/util.cpp --- a/liboggplayer-src/src/util.cpp Tue Aug 06 23:27:37 2013 +0300 +++ b/liboggplayer-src/src/util.cpp Tue Aug 06 23:45:05 2013 +0300 @@ -5,10 +5,6 @@ int OggPlayer::Imp::queue_page(ogg_page * page) { if (theora_p) ogg_stream_pagein(&o_tsstate, page); -#ifdef VORBIS_SUPPORT - if (vorbis_p) - ogg_stream_pagein(&o_vsstate, page); -#endif return 0; }