Skip to content

Commit

Permalink
fix video drop problem
Browse files Browse the repository at this point in the history
  • Loading branch information
microcai committed Nov 29, 2012
1 parent 9998972 commit 4dae589
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 deletions audio/sdl_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define UINT64_C(c) c ## ULL

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
Expand Down Expand Up @@ -91,12 +91,14 @@ void sdl_audio_render::sdl_audio_callback(void* userdata, Uint8* stream, int len

void sdl_audio_render::audio_callback(Uint8* stream, int len)
{
// boost::mutex::scoped_lock l(m_mutex);

ssize_t readed=0;
// logger("sdl ask for %d length of data %p",len,stream);

while(readed < len){

ssize_t ret = read(adfd[1],stream,len - readed);
ssize_t ret = read(adfd[0],stream,len - readed);
if(ret >= 0){
readed += ret;
}else{
Expand All @@ -108,8 +110,10 @@ void sdl_audio_render::audio_callback(Uint8* stream, int len)

int sdl_audio_render::play_audio(uint8_t* data, uint32_t size)
{
// boost::mutex::scoped_lock l(m_mutex);

// push to stack
ssize_t ret = write(adfd[0],data,size);
ssize_t ret = write(adfd[1],data,size);
if(ret != size){
logger("write audio error\b");
exit(1);
Expand All @@ -129,20 +133,21 @@ void sdl_audio_render::destory_audio()

bool sdl_audio_render::init_audio(void* ctx, int channels, int bits_per_sample, int sample_rate, int format)
{
socketpair(AF_UNIX,SOCK_CLOEXEC|SOCK_STREAM,0,adfd);
logger("socket created for audio %d %d\n",adfd[0],adfd[1]);
pipe(adfd);
logger("pipe created for audio %d %d\n",adfd[0],adfd[1]);
SDL_AudioSpec fmt[1];// = new SDL_AudioSpec;

/* Set 16-bit stereo audio at 22Khz */
fmt->silence = 0;
fmt->freq = sample_rate;
fmt->format = AUDIO_S16;
fmt->channels = channels;
fmt->samples = 1024; /* A good value for games */
fmt->samples = 1024;
fmt->callback = sdl_audio_callback;
fmt->userdata = this;

bool ret = SDL_OpenAudio(fmt,0)>=0;
SDL_PauseAudio(0);
// m_mutex.lock();
return ret;
}
1 change: 1 addition & 0 deletions audio/sdl_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class sdl_audio_render:public audio_render
void audio_callback(Uint8 *stream, int len);
private:
int adfd[2];
boost::mutex m_mutex;
// boost::mutex adqueue_mutex;
// boost::condition_variable adqueue_mutex_cond;
// std::queue<std::pair<uint8_t*,uint32_t> > adqueue;
Expand Down
2 changes: 1 addition & 1 deletion linux/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int player::open(const char* movie, int media_type)
enable_calc_frame_rate(m_avplay);
enable_calc_bit_rate(m_avplay);
//FIXME, don't know why audio sync cause frame drop
m_avplay->m_av_sync_type = AV_SYNC_VIDEO_MASTER;
//m_avplay->m_av_sync_type = AV_SYNC_VIDEO_MASTER;

return 0;

Expand Down

0 comments on commit 4dae589

Please sign in to comment.