forked from huceke/omxplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OMXReader.h
204 lines (186 loc) · 6.07 KB
/
OMXReader.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#ifndef _OMX_READER_H_
#define _OMX_READER_H_
#include "DllAvUtil.h"
#include "DllAvFormat.h"
#include "DllAvFilter.h"
#include "DllAvCodec.h"
#include "OMXStreamInfo.h"
#ifdef STANDALONE
#include "OMXThread.h"
#else
#include "threads/Thread.h"
#endif
#include <queue>
#include "OMXStreamInfo.h"
#ifdef STANDALONE
#include "File.h"
#else
#include "xbmc/filesystem/File.h"
#endif
#include <sys/types.h>
#include <string>
using namespace XFILE;
using namespace std;
#define MAX_OMX_CHAPTERS 64
#define MAX_OMX_STREAMS 100
#define OMX_PLAYSPEED_PAUSE 0
#define OMX_PLAYSPEED_NORMAL 1
#ifndef FFMPEG_FILE_BUFFER_SIZE
#define FFMPEG_FILE_BUFFER_SIZE 32768 // default reading size for ffmpeg
#endif
#ifndef MAX_STREAMS
#define MAX_STREAMS 100
#endif
typedef struct OMXChapter
{
std::string name;
int64_t seekto_ms;
double ts;
} OMXChapter;
class OMXReader;
typedef struct OMXPacket
{
double pts; // pts in DVD_TIME_BASE
double dts; // dts in DVD_TIME_BASE
double now; // dts in DVD_TIME_BASE
double duration; // duration in DVD_TIME_BASE if available
int size;
uint8_t *data;
int stream_index;
COMXStreamInfo hints;
enum AVMediaType codec_type;
} OMXPacket;
enum OMXStreamType
{
OMXSTREAM_NONE = 0,
OMXSTREAM_AUDIO = 1,
OMXSTREAM_VIDEO = 2,
OMXSTREAM_SUBTITLE = 3
};
typedef struct OMXStream
{
char language[4];
std::string name;
std::string codec_name;
AVStream *stream;
OMXStreamType type;
int id;
void *extradata;
unsigned int extrasize;
unsigned int index;
COMXStreamInfo hints;
} OMXStream;
class OMXReader
{
protected:
int m_video_index;
int m_audio_index;
int m_subtitle_index;
int m_video_count;
int m_audio_count;
int m_subtitle_count;
DllAvUtil m_dllAvUtil;
DllAvCodec m_dllAvCodec;
DllAvFormat m_dllAvFormat;
bool m_open;
std::string m_filename;
bool m_bMatroska;
bool m_bAVI;
bool m_bMpeg;
XFILE::CFile *m_pFile;
AVFormatContext *m_pFormatContext;
AVIOContext *m_ioContext;
bool m_eof;
OMXChapter m_chapters[MAX_OMX_CHAPTERS];
OMXStream m_streams[MAX_STREAMS];
int m_chapter_count;
double m_iCurrentPts;
int m_speed;
unsigned int m_program;
//#ifdef STANDALONE
// void flush_packet_queue(AVFormatContext *s);
// void av_read_frame_flush(AVFormatContext *s);
//#endif
pthread_mutex_t m_lock;
void Lock();
void UnLock();
bool SetActiveStreamInternal(OMXStreamType type, unsigned int index);
bool m_seek;
private:
public:
OMXReader();
~OMXReader();
bool Open(std::string filename, bool dump_format);
void ClearStreams();
bool Close();
//void FlushRead();
bool SeekTime(int64_t seek_ms, int seek_flags, double *startpts);
AVMediaType PacketType(OMXPacket *pkt);
OMXPacket *Read();
void Process();
bool GetStreams();
void AddStream(int id);
bool IsActive(int stream_index);
bool IsActive(OMXStreamType type, int stream_index);
bool GetHints(AVStream *stream, COMXStreamInfo *hints);
bool GetHints(OMXStreamType type, unsigned int index, COMXStreamInfo &hints);
bool GetHints(OMXStreamType type, COMXStreamInfo &hints);
bool IsEof();
int AudioStreamCount() { return m_audio_count; };
int VideoStreamCount() { return m_video_count; };
int SubtitleStreamCount() { return m_subtitle_count; };
bool SetActiveStream(OMXStreamType type, unsigned int index);
int GetChapterCount() { return m_chapter_count; };
OMXChapter GetChapter(unsigned int chapter) { return m_chapters[(chapter > MAX_OMX_CHAPTERS) ? MAX_OMX_CHAPTERS : chapter]; };
static void FreePacket(OMXPacket *pkt);
static OMXPacket *AllocPacket(int size);
void SetSpeed(int iSpeed);
void UpdateCurrentPTS();
double ConvertTimestamp(int64_t pts, int den, int num);
double ConvertTimestamp(int64_t pts, AVRational *time_base);
int GetChapter();
void GetChapterName(std::string& strChapterName);
bool SeekChapter(int chapter, double* startpts);
int GetAudioIndex() { return (m_audio_index >= 0) ? m_streams[m_audio_index].index : -1; };
int GetSubtitleIndex() { return (m_subtitle_index >= 0) ? m_streams[m_subtitle_index].index : -1; };
int GetRelativeIndex(size_t index)
{
assert(index < MAX_STREAMS);
return m_streams[index].index;
}
int GetStreamLength();
static double NormalizeFrameduration(double frameduration);
bool IsMpegVideo() { return m_bMpeg; };
bool IsMatroska() { return m_bMatroska; };
std::string GetCodecName(OMXStreamType type);
std::string GetCodecName(OMXStreamType type, unsigned int index);
std::string GetStreamCodecName(AVStream *stream);
std::string GetStreamLanguage(OMXStreamType type, unsigned int index);
std::string GetStreamName(OMXStreamType type, unsigned int index);
std::string GetStreamType(OMXStreamType type, unsigned int index);
bool CanSeek();
#ifndef STANDALONE
int GetSourceBitrate();
#endif
};
#endif