blob: d38a8e5eb1b817fc472bf0b9dc09f458d7900052 (
plain)
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
|
/*
* codec.cpp
*
* Created on: 13.10.2012
* Author: savop
*/
#include "../include/tools/codec.h"
namespace upnp {
namespace codec {
cFormatContext::cFormatContext()
: formatCtx(NULL)
{
av_register_all();
}
cFormatContext::~cFormatContext(){
av_free(formatCtx);
}
bool cFormatContext::Open(const string& file){
if(avformat_open_input(&formatCtx, file.c_str(), NULL, NULL) == 0){
if(avformat_find_stream_info(formatCtx, NULL) == 0){
return true;
}
}
return false;
}
const AVCodec* cFormatContext::GetCodec(AVMediaType Type) const {
return avcodec_find_decoder(GetCodecContext(Type)->codec_id);
}
const AVCodecContext* cFormatContext::GetCodecContext(AVMediaType Type) const {
const AVStream* strm = GetStream(Type);
return strm?strm->codec:NULL;
}
const AVStream* cFormatContext::GetStream(AVMediaType Type) const {
if(!formatCtx) return NULL;
int Stream = -1; unsigned int i;
for(i = 0; i < formatCtx->nb_streams; i++){
if(formatCtx->streams[i]->codec->codec_type == Type){
Stream = i;
break;
}
}
if(Stream == -1){
return NULL;
}
return formatCtx->streams[Stream];
}
AVFormatContext* cFormatContext::operator*() const {
return formatCtx;
}
} // namespace codec
} // namespace upnp
|