Skip to content

Commit eb1e0e9

Browse files
committed
change media_source input mode.
1 parent 1fd00ae commit eb1e0e9

File tree

8 files changed

+449
-432
lines changed

8 files changed

+449
-432
lines changed

avcore/player_impl.cpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -625,23 +625,23 @@ void player_impl::fill_rectange(HWND hWnd, HDC hdc, RECT win_rect, RECT client_r
625625
DeleteObject(memBM);
626626
}
627627

628-
void player_impl::init_file_source(media_source *ms)
628+
void player_impl::init_file_source(source_context *sc)
629629
{
630-
ms->init_source = file_init_source;
631-
ms->read_data = file_read_data;
632-
ms->close = file_close;
633-
ms->destory = file_destory;
634-
ms->offset = 0;
630+
sc->init_source = file_init_source;
631+
sc->read_data = file_read_data;
632+
sc->close = file_close;
633+
sc->destory = file_destory;
634+
sc->offset = 0;
635635
}
636636

637-
void player_impl::init_torrent_source(media_source *ms)
637+
void player_impl::init_torrent_source(source_context *sc)
638638
{
639-
ms->init_source = bt_init_source;
640-
ms->read_data = bt_read_data;
641-
ms->bt_media_info = bt_media_info;
642-
ms->close = bt_close;
643-
ms->destory = bt_destory;
644-
ms->offset = 0;
639+
sc->init_source = bt_init_source;
640+
sc->read_data = bt_read_data;
641+
sc->bt_media_info = bt_media_info;
642+
sc->close = bt_close;
643+
sc->destory = bt_destory;
644+
sc->offset = 0;
645645
}
646646

647647
void player_impl::init_audio(ao_context *ao)
@@ -752,7 +752,6 @@ BOOL player_impl::open(LPCTSTR movie, int media_type)
752752

753753
// 初始化文件媒体源.
754754
init_file_source(m_source);
755-
m_source->data_len = len + 1;
756755
}
757756

758757
if (media_type == MEDIA_TYPE_BT)
@@ -770,7 +769,6 @@ BOOL player_impl::open(LPCTSTR movie, int media_type)
770769
free(torrent_data);
771770

772771
// 初始化torrent媒体源.
773-
m_source->data_len = file_lentgh;
774772
init_torrent_source(m_source);
775773
}
776774

@@ -782,7 +780,6 @@ BOOL player_impl::open(LPCTSTR movie, int media_type)
782780
break;
783781
// 插入到媒体列表.
784782
m_media_list.insert(std::make_pair(filename, filename));
785-
m_source->data_len = len;
786783
}
787784

788785
if (media_type == MEDIA_TYPE_RTSP)
@@ -793,7 +790,6 @@ BOOL player_impl::open(LPCTSTR movie, int media_type)
793790
break;
794791
// 插入到媒体列表.
795792
m_media_list.insert(std::make_pair(filename, filename));
796-
m_source->data_len = len;
797793
}
798794

799795
// 初始化avplay.
@@ -804,8 +800,8 @@ BOOL player_impl::open(LPCTSTR movie, int media_type)
804800
if (media_type == MEDIA_TYPE_BT)
805801
{
806802
int i = 0;
807-
media_info *media = m_avplay->m_media_source->media;
808-
for (; i < m_avplay->m_media_source->media_size; i++)
803+
media_info *media = m_avplay->m_source_ctx->media;
804+
for (; i < m_avplay->m_source_ctx->media_size; i++)
809805
{
810806
std::string name;
811807
name = media->name;

avcore/player_impl.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ class player_impl
133133
LRESULT win_wnd_proc(HWND, UINT, WPARAM, LPARAM);
134134

135135
// 播放器相关的函数.
136-
void init_file_source(media_source *ms);
137-
void init_torrent_source(media_source *ms);
136+
void init_file_source(source_context *sc);
137+
void init_torrent_source(source_context *sc);
138138
void init_audio(ao_context *ao);
139139
void init_video(vo_context *vo);
140140

@@ -148,13 +148,15 @@ class player_impl
148148
HBRUSH m_brbackground;
149149
WNDPROC m_old_win_proc;
150150

151-
// 播放器相关.
151+
// 播放器主要由下面几个部件组成.
152+
// avplay 是整合source_context和ao_context,vo_context的大框架.
153+
// 由 source_context实现数据读入视频数据.
154+
// 由 avplay负责分离音视并解码.
155+
// 最后由ao_context和vo_context分别负责输出音频和视频.
152156
avplay *m_avplay;
153-
// audio_render *m_audio;
157+
source_context *m_source;
154158
ao_context *m_audio;
155-
// video_render *m_video;
156159
vo_context *m_video;
157-
media_source *m_source;
158160

159161
int (*m_draw_frame)(void *ctx, AVFrame* data, int pix_fmt);
160162

libav/include/defs.h

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
2-
// common.h
3-
// ~~~~~~~~
2+
// defs.h
3+
// ~~~~~~
44
//
55
// Copyright (c) 2012 Jack ([email protected])
66
//
@@ -10,6 +10,62 @@
1010

1111
#include "libavcodec/avcodec.h"
1212

13+
/* 媒体数据源接口. */
14+
#define MEDIA_TYPE_FILE 0
15+
#define MEDIA_TYPE_BT 1
16+
#define MEDIA_TYPE_HTTP 2
17+
#define MEDIA_TYPE_RTSP 3
18+
19+
/* 媒体文件信息. */
20+
typedef struct media_info
21+
{
22+
char *name; // 文件名.
23+
int64_t start_pos; // 起始位置.
24+
int64_t file_size; // 文件大小.
25+
} media_info;
26+
27+
/* 媒体数据源接口. */
28+
typedef struct source_context
29+
{
30+
int (*init_source)(void *ctx);
31+
/*
32+
* name 输出视频名称, 需要调用者分配内存.
33+
* pos 输入查询的序号, 从0开始; 输出为视频在bt下载中的起始位置偏移.
34+
* size 输入name缓冲区长度, 输出视频大小.
35+
* 返回torrent中的视频媒体个数, 返回-1表示出错.
36+
*/
37+
int (*bt_media_info)(void *ctx, char *name, int64_t *pos, int64_t *size);
38+
int (*read_data)(void *ctx, char* buff, int64_t offset, int buf_size);
39+
void (*close)(void *ctx);
40+
void (*destory)(void *ctx);
41+
/* io_dev是保存内部用于访问实际数据的对象指针. */
42+
void *io_dev;
43+
/*
44+
* 数据类型, 可以是以下值
45+
* MEDIA_TYPE_FILE、MEDIA_TYPE_BT、MEDIA_TYPE_HTTP、MEDIA_TYPE_RTSP
46+
* 说明: 由于http和rtsp直接使用了ffmpeg的demux, 所以就无需初始
47+
* 化上面的各函数指针.
48+
*/
49+
int type;
50+
/*
51+
* 如果类型是MEDIA_TYPE_BT, 则此指向bt种子数据.
52+
*/
53+
char *torrent_data;
54+
int torrent_len;
55+
56+
/* torrent中的媒体文件信息, 只有在打开
57+
* torrent之后, 这里面才可能有数据.
58+
*/
59+
media_info *media;
60+
/*
61+
* 媒体文件信息个数, 主要为BT文件播放设计, 因为一个torrent中可
62+
* 能存在多个视频文件.
63+
*/
64+
int media_size;
65+
/* 记录当前播放数据偏移, 绝对位置. */
66+
int64_t offset;
67+
} source_context;
68+
1369
/* 视频播放结构定义. */
1470
typedef struct vo_context
1571
{

0 commit comments

Comments
 (0)