Skip to content

Commit

Permalink
全屏功能
Browse files Browse the repository at this point in the history
  • Loading branch information
microcai committed Dec 18, 2012
1 parent 06757b5 commit 671ac65
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 29 deletions.
24 changes: 14 additions & 10 deletions linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ int main ( int argc, char *argv[] )

while ( true )
{
int w=-1, h=-1;
SDL_Event event;
SDL_WaitEvent ( &event );

Expand All @@ -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){
Expand Down
14 changes: 14 additions & 0 deletions linux/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

10 changes: 6 additions & 4 deletions linux/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
class player
{
public:
// 播放控制
// 播放控制.
void fwd(); //快进
void bwd(); //快退

// 调节大小
// 调节大小.
void resize(int, int);
// 全屏.
void togglefs();

private:
bool HasWindow(){return true;};
Expand All @@ -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);

Expand All @@ -63,6 +63,8 @@ class player
int m_video_width;
int m_video_height;
int m_cur_index;

bool m_fs;
};

#endif // PLAYER_H
41 changes: 27 additions & 14 deletions video/sdl_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion video/sdl_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 671ac65

Please sign in to comment.