diff --git a/linux/main.cpp b/linux/main.cpp index bc03638..829585e 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -63,6 +63,7 @@ int main ( int argc, char *argv[] ) while ( true ) { + int w=-1, h=-1; SDL_Event event; SDL_WaitEvent ( &event ); @@ -73,16 +74,19 @@ int main ( int argc, char *argv[] ) } if ( event.type == SDL_KEYDOWN ) { - if ( event.key.keysym.sym == SDLK_RIGHT ) - { - ply.fwd(); - } - else if ( event.key.keysym.sym == SDLK_LEFT ) - { - ply.bwd(); - } - else if (event.key.keysym.sym == SDLK_f){ - //SDL_SetVideoMode(0, 0, 32) + switch (event.key.keysym.sym) + { + case SDLK_RIGHT: + ply.fwd(); + break; + case SDLK_LEFT: + ply.bwd(); + break; + case SDLK_f: + ply.togglefs(); + break; + case SDLK_q: + return 0; } } if ( event.type == SDL_VIDEORESIZE){ diff --git a/linux/player.cpp b/linux/player.cpp index c04a0f6..ab9b0bd 100644 --- a/linux/player.cpp +++ b/linux/player.cpp @@ -296,3 +296,17 @@ void player::resize(int w, int h) { m_video->re_size(m_video, w, h); } + +void player::togglefs() +{ + if ( m_fs = ! m_fs ){ + m_avplay->m_video_st->codec->width; + m_avplay->m_video_st->codec->height; + + this->resize(m_avplay->m_video_st->codec->width,m_avplay->m_video_st->codec->height); + }else{ + SDL_Rect** mode = SDL_ListModes(NULL,SDL_FULLSCREEN); + this->resize(mode[0]->w, mode[0]->h); + } +} + diff --git a/linux/player.h b/linux/player.h index b9407f5..d0c61f2 100644 --- a/linux/player.h +++ b/linux/player.h @@ -26,12 +26,14 @@ class player { public: - // 播放控制 + // 播放控制. void fwd(); //快进 void bwd(); //快退 - // 调节大小 + // 调节大小. void resize(int, int); + // 全屏. + void togglefs(); private: bool HasWindow(){return true;}; @@ -42,8 +44,6 @@ class player void init_audio(ao_context *ao); void init_video(vo_context *vo); - int (*m_draw_frame)(void *ctx, AVFrame* data, int pix_fmt, double pts); - // 实时处理视频渲染的视频数据, 在这里完成比较加字幕, 加水印等操作. static int draw_frame(void *ctx, AVFrame* data, int pix_fmt, double pts); @@ -63,6 +63,8 @@ class player int m_video_width; int m_video_height; int m_cur_index; + + bool m_fs; }; #endif // PLAYER_H diff --git a/video/sdl_render.cpp b/video/sdl_render.cpp index 672982f..a007f54 100644 --- a/video/sdl_render.cpp +++ b/video/sdl_render.cpp @@ -102,15 +102,19 @@ sdl_render::render_one_frame(AVFrame * data, int pix_fmt) data->linesize[2] }; + m_swsctx = sws_getCachedContext(m_swsctx, m_image_width, m_image_height, + (PixelFormat)m_pix_fmt, sfc->w, sfc->h, PIX_FMT_YUV420P, + SWS_BICUBIC, NULL, NULL, NULL); + SDL_LockYUVOverlay(m_yuv); pict.data[0] = m_yuv->pixels[0]; - pict.data[1] = m_yuv->pixels[1]; - pict.data[2] = m_yuv->pixels[2]; + pict.data[1] = m_yuv->pixels[2]; + pict.data[2] = m_yuv->pixels[1]; pict.linesize[0] = m_yuv->pitches[0]; - pict.linesize[1] = m_yuv->pitches[1]; - pict.linesize[2] = m_yuv->pitches[2]; + pict.linesize[1] = m_yuv->pitches[2]; + pict.linesize[2] = m_yuv->pitches[1]; sws_scale(m_swsctx, pixels, linesize, 0, m_image_height, pict.data, pict.linesize); @@ -131,24 +135,33 @@ sdl_render::render_one_frame(AVFrame * data, int pix_fmt) void sdl_render::re_size(int w, int h) { - m_swsctx = - sws_getCachedContext(m_swsctx, m_image_width, m_image_height, - PIX_FMT_YUV420P, w, h, PIX_FMT_YUV420P, - SWS_BICUBIC, NULL, NULL, NULL); - - logger("resize happned\n"); - boost::mutex::scoped_lock l(renderlock); - SDL_FreeYUVOverlay(this->m_yuv); - this->m_yuv = SDL_CreateYUVOverlay(w, h, SDL_IYUV_OVERLAY, sfc); + boost::mutex::scoped_lock l(renderlock); + + //FIXME + //resize 有办法传递全屏信息就好了 + int fw, fh; + SDL_Rect** mode = SDL_ListModes(NULL,SDL_FULLSCREEN); + + fw = mode[0]->w ; fh = mode[0]->h; + + bool fs=false; + if ( w == fw && h == fh ) + fs = true; + sfc = SDL_SetVideoMode(w, h, 32, fs? SDL_FULLSCREEN : SDL_RESIZABLE); + SDL_FreeYUVOverlay(this->m_yuv); + this->m_yuv = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, sfc); } bool sdl_render::init_render(void *ctx, int w, int h, int pix_fmt) { m_swsctx = NULL; + m_pix_fmt = pix_fmt; + if (!SDL_WasInit(SDL_INIT_VIDEO)) SDL_InitSubSystem(SDL_INIT_VIDEO); - sfc = SDL_SetVideoMode(w, h, 32, SDL_RESIZABLE); + + SDL_SetVideoMode(w, h, 32, SDL_RESIZABLE); m_image_height = h; m_image_width = w; diff --git a/video/sdl_render.h b/video/sdl_render.h index 0bdb112..ee18eef 100644 --- a/video/sdl_render.h +++ b/video/sdl_render.h @@ -45,8 +45,9 @@ class sdl_render : public video_render SDL_Overlay* m_yuv; SDL_Surface* sfc; boost::mutex renderlock; + int m_pix_fmt; int m_image_width, m_image_height; - SwsContext* m_swsctx; + SwsContext* m_swsctx; }; #endif // SDL_RENDER_H