forked from Jackarain/avplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemux.cpp
86 lines (71 loc) · 2.1 KB
/
demux.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "internal.h"
#include "globals.h"
#include "demux.h"
#include "generic_demux.h"
// 具体的demux组件实现.
EXPORT_API int generic_init_demux(struct demux_context *demux_ctx)
{
generic_demux_info &generic_info = demux_ctx->info.generic;
generic_demux *demux = new generic_demux();
generic_demux_data d;
// 保存文件名到d, 以作为参数传入generic_demux中打开.
d.file_name = std::string(generic_info.file_name);
// 保存到demux_context.priv中做为私有的上下文.
demux_ctx->priv = (void*)demux;
// 保存数据源类型.
d.type = demux_ctx->type;
// 执行打开操作.
if (demux->open(d))
{
demux_ctx->base_info = demux->base_info();
return 0;
}
return -1;
}
EXPORT_API int generic_read_packet(struct demux_context *demux_ctx, AVPacket *pkt)
{
generic_demux *demux = (generic_demux*)demux_ctx->priv;
if (demux->read_packet(pkt))
return 0;
return -1;
}
EXPORT_API int generic_packet_seek(struct demux_context *demux_ctx, int64_t timestamp)
{
generic_demux *demux = (generic_demux*)demux_ctx->priv;
if (demux->seek_packet(timestamp))
return 0;
return -1;
}
EXPORT_API int generic_read_pause(struct demux_context *demux_ctx)
{
generic_demux *demux = (generic_demux*)demux_ctx->priv;
return demux->read_pause();
}
EXPORT_API int generic_read_play(struct demux_context *demux_ctx)
{
generic_demux *demux = (generic_demux*)demux_ctx->priv;
return demux->read_play();
}
EXPORT_API int generic_stream_index(struct demux_context *demux_ctx, enum AVMediaType type)
{
generic_demux *demux = (generic_demux*)demux_ctx->priv;
int index = -1;
if (demux->stream_index(type, index))
return index;
return -1;
}
EXPORT_API enum AVCodecID generic_query_avcodec_id(struct demux_context *demux_ctx, int index)
{
generic_demux *demux = (generic_demux*)demux_ctx->priv;
enum AVCodecID id;
if (demux->query_avcodec_id(index, id))
return id;
return AV_CODEC_ID_NONE;
}
EXPORT_API void generic_destory(struct demux_context *demux_ctx)
{
generic_demux *demux = (generic_demux*)demux_ctx->priv;
demux->close(); // 关闭demux.
delete demux; // 释放资源.
demux_ctx->priv = NULL;
}