Skip to content

Commit

Permalink
change audio && video output export mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackarain committed May 17, 2012
1 parent 10308d9 commit aa9b018
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 84 deletions.
17 changes: 11 additions & 6 deletions audio/audio_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,39 @@ EXPORT_API void wave_destory_audio(void* ctx)
}


EXPORT_API int dsound_init_audio(void** ctx, void* user_data,
EXPORT_API int dsound_init_audio(void* ctx, void* user_data,
uint32_t channels, uint32_t bits_per_sample, uint32_t sample_rate, int format)
{
dsound_render* dsound = new dsound_render;
*ctx = dsound;
ao_context *ao = (ao_context*)ctx;
dsound_render* dsound = NULL;
ao->audio_dev = (void*)(dsound = new dsound_render);
return dsound->init_audio((void*)dsound, channels, bits_per_sample, sample_rate, format) ? 0 : -1;
}

EXPORT_API int dsound_play_audio(void* ctx, uint8_t* data, uint32_t size)
{
dsound_render* dsound = (dsound_render*)ctx;
ao_context *ao = (ao_context*)ctx;
dsound_render* dsound = (dsound_render*)ao->audio_dev;
return dsound->play_audio(data, size);
}

EXPORT_API void dsound_audio_control(void* ctx, double vol)
{
dsound_render* dsound = (dsound_render*)ctx;
ao_context *ao = (ao_context*)ctx;
dsound_render* dsound = (dsound_render*)ao->audio_dev;
control_vol_t ctrl_vol = { vol, vol };
dsound->audio_control(CONTROL_SET_VOLUME, &ctrl_vol);
}

EXPORT_API void dsound_destory_audio(void* ctx)
{
dsound_render* dsound = (dsound_render*)ctx;
ao_context *ao = (ao_context*)ctx;
dsound_render* dsound = (dsound_render*)ao->audio_dev;
if (dsound)
{
dsound->destory_audio();
delete dsound;
ao->audio_dev = NULL;
}
}

Expand Down
8 changes: 1 addition & 7 deletions audio/audio_out.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@
extern "C" {
#endif

// EXPORT_API int wave_init_audio(void** ctx, uint32_t channels,
// uint32_t bits_per_sample, uint32_t sample_rate, int format);
// EXPORT_API int wave_play_audio(void* ctx, uint8_t* data, uint32_t size);
// EXPORT_API void wave_audio_control(void* ctx, double vol);
// EXPORT_API void wave_destory_audio(void* ctx);

EXPORT_API int wave_init_audio(void* ctx, uint32_t channels,
uint32_t bits_per_sample, uint32_t sample_rate, int format);
EXPORT_API int wave_play_audio(void* ctx, uint8_t* data, uint32_t size);
EXPORT_API void wave_audio_control(void* ctx, double vol);
EXPORT_API void wave_destory_audio(void* ctx);


EXPORT_API int dsound_init_audio(void** ctx, void* user_data, uint32_t channels,
EXPORT_API int dsound_init_audio(void* ctx, void* user_data, uint32_t channels,
uint32_t bits_per_sample, uint32_t sample_rate, int format);
EXPORT_API int dsound_play_audio(void* ctx, uint8_t* data, uint32_t size);
EXPORT_API void dsound_audio_control(void* ctx, double vol);
Expand Down
26 changes: 11 additions & 15 deletions avcore/player_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,8 @@ LRESULT player_impl::win_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpa
{
RECT window;
GetClientRect(hwnd, &window);
if (m_video && m_video->ctx)
m_video->re_size(m_video->ctx,
LOWORD(lparam), HIWORD(lparam));
if (m_video && m_video->video_dev)
m_video->re_size(m_video, LOWORD(lparam), HIWORD(lparam));
InvalidateRect(hwnd, NULL, TRUE);
}
break;
Expand All @@ -538,8 +537,8 @@ LRESULT player_impl::win_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpa

void player_impl::win_paint(HWND hwnd, HDC hdc)
{
if (m_video && m_video->ctx &&
m_video->use_overlay(m_video->ctx) != -1)
if (m_video && m_video->video_dev &&
m_video->use_overlay(m_video) != -1)
{
RECT client_rect;
GetClientRect(hwnd, &client_rect);
Expand Down Expand Up @@ -652,18 +651,16 @@ void player_impl::init_audio(ao_context *ao)
ao->destory_audio = wave_destory_audio;
}

void player_impl::init_video(video_render *vo)
void player_impl::init_video(vo_context *vo)
{
void *ctx = NULL;
int ret = 0;

do
{
ret = ddraw_init_video(&ctx, (void*)m_hwnd, 10, 10, PIX_FMT_YUV420P);
ddraw_destory_render(ctx);
ret = ddraw_init_video((void*)vo, 10, 10, PIX_FMT_YUV420P);
ddraw_destory_render(vo);
if (ret == 0)
{
m_draw_frame = ddraw_render_one_frame;
vo->init_video = ddraw_init_video;
vo->render_one_frame = ddraw_render_one_frame;
vo->re_size = ddraw_re_size;
Expand All @@ -673,11 +670,10 @@ void player_impl::init_video(video_render *vo)
break;
}

ret = d3d_init_video(&ctx, (void*)m_hwnd, 10, 10, PIX_FMT_YUV420P);
d3d_destory_render(ctx);
ret = d3d_init_video((void*)vo, 10, 10, PIX_FMT_YUV420P);
d3d_destory_render(vo);
if (ret == 0)
{
m_draw_frame = d3d_render_one_frame;
vo->init_video = d3d_init_video;
vo->render_one_frame = d3d_render_one_frame;
vo->re_size = d3d_re_size;
Expand All @@ -687,8 +683,8 @@ void player_impl::init_video(video_render *vo)
break;
}

ret = ogl_init_video(&ctx, (void*)m_hwnd, 10, 10, PIX_FMT_YUV420P);
ogl_destory_render(ctx);
ret = ogl_init_video((void*)vo, 10, 10, PIX_FMT_YUV420P);
ogl_destory_render(vo);
if (ret == 0)
{
vo->init_video = ogl_init_video;
Expand Down
5 changes: 3 additions & 2 deletions avcore/player_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class player_impl
void init_file_source(media_source *ms);
void init_torrent_source(media_source *ms);
void init_audio(ao_context *ao);
void init_video(video_render *vo);
void init_video(vo_context *vo);

// 实时处理视频渲染的视频数据, 在这里完成比较加字幕, 加水印等操作.
void draw_frame(void *ctx, AVFrame* data, int pix_fmt);
Expand All @@ -152,7 +152,8 @@ class player_impl
avplay *m_avplay;
// audio_render *m_audio;
ao_context *m_audio;
video_render *m_video;
// video_render *m_video;
vo_context *m_video;
media_source *m_source;

int (*m_draw_frame)(void *ctx, AVFrame* data, int pix_fmt);
Expand Down
34 changes: 18 additions & 16 deletions libav/src/avplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ ao_context* alloc_audio_render()

void free_audio_render(ao_context *render)
{
if (render->ctx)
if (render->audio_dev)
render->destory_audio(render);
free(render);
}
Expand All @@ -475,7 +475,7 @@ vo_context* alloc_video_render(void *user_data)

void free_video_render(vo_context *render)
{
if (render->ctx)
if (render->video_dev)
render->destory_video(render);
free(render);
}
Expand Down Expand Up @@ -742,13 +742,13 @@ void configure(avplay *play, void* param, int type)
{
if (play->m_ao_ctx && play->m_ao_ctx->audio_dev)
free_audio_render(play->m_ao_ctx);
play->m_ao_ctx = param;
play->m_ao_ctx = (ao_context*)param;
}
if (type == VIDEO_RENDER)
{
if (play->m_video_render && play->m_video_render->ctx)
play->m_video_render->destory_video(play->m_video_render->ctx);
play->m_video_render = param;
if (play->m_vo_ctx && play->m_vo_ctx->video_dev)
free_video_render(play->m_vo_ctx);
play->m_vo_ctx = (vo_context*)param;
}
if (type == MEDIA_SOURCE)
{
Expand Down Expand Up @@ -851,10 +851,10 @@ void stop(avplay *play)
free_audio_render(play->m_ao_ctx);
play->m_ao_ctx = NULL;
}
if (play->m_video_render)
if (play->m_vo_ctx)
{
free_video_render(play->m_video_render);
play->m_video_render = NULL;
free_video_render(play->m_vo_ctx);
play->m_vo_ctx = NULL;
}
if (play->m_avio_ctx)
{
Expand Down Expand Up @@ -1692,12 +1692,13 @@ void* video_render_thrd(void *param)
ret = get_queue(&play->m_video_dq, &video_frame);
if (ret != -1)
{
if (!inited && play->m_video_render)
if (!inited && play->m_vo_ctx)
{
inited = 1;
ret = play->m_video_render->init_video(&play->m_video_render->ctx,
play->m_video_render->user_data, play->m_video_ctx->width,
play->m_video_ctx->height, play->m_video_ctx->pix_fmt);
ret = play->m_vo_ctx->init_video(play->m_vo_ctx,
play->m_video_ctx->width,
play->m_video_ctx->height,
play->m_video_ctx->pix_fmt);
if (ret != 0)
inited = -1;
else
Expand Down Expand Up @@ -1837,10 +1838,11 @@ void* video_render_thrd(void *param)
if (play->m_seeking == SEEKING_FLAG)
play->m_seeking = NOSEEKING_FLAG;

if (inited == 1 && play->m_video_render)
if (inited == 1 && play->m_vo_ctx)
{
play->m_video_render->render_one_frame(
play->m_video_render->ctx, &video_frame,
play->m_vo_ctx->render_one_frame(
play->m_vo_ctx,
&video_frame,
play->m_video_ctx->pix_fmt);
if (delay != 0)
Sleep(4);
Expand Down
3 changes: 1 addition & 2 deletions libav/src/avplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,9 @@ typedef struct avplay
AVIOContext *m_avio_ctx;
unsigned char *m_io_buffer;
/* 当前音频渲染器. */
/*audio_render *m_audio_render;*/
ao_context *m_ao_ctx;
/* 当前视频渲染器. */
video_render *m_video_render;
/*video_render *m_video_render;*/
vo_context *m_vo_ctx;

/* 当前音频播放buffer大小. */
Expand Down
Loading

0 comments on commit aa9b018

Please sign in to comment.