PageRenderTime 89ms CodeModel.GetById 54ms app.highlight 27ms RepoModel.GetById 3ms app.codeStats 0ms

/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.h

http://github.com/xbmc/xbmc
C++ Header | 162 lines | 111 code | 29 blank | 22 comment | 0 complexity | 7f73720a3c0c126705f78bbbff2a28b4 MD5 | raw file
  1#pragma once
  2
  3/*
  4 *      Copyright (C) 2005-2013 Team XBMC
  5 *      http://xbmc.org
  6 *
  7 *  This Program is free software; you can redistribute it and/or modify
  8 *  it under the terms of the GNU General Public License as published by
  9 *  the Free Software Foundation; either version 2, or (at your option)
 10 *  any later version.
 11 *
 12 *  This Program is distributed in the hope that it will be useful,
 13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 *  GNU General Public License for more details.
 16 *
 17 *  You should have received a copy of the GNU General Public License
 18 *  along with XBMC; see the file COPYING.  If not, see
 19 *  <http://www.gnu.org/licenses/>.
 20 *
 21 */
 22
 23#include "DVDDemux.h"
 24#include "DllAvFormat.h"
 25#include "DllAvCodec.h"
 26#include "DllAvUtil.h"
 27
 28#include "threads/CriticalSection.h"
 29#include "threads/SystemClock.h"
 30
 31#include <map>
 32
 33class CDVDDemuxFFmpeg;
 34class CURL;
 35
 36class CDemuxStreamVideoFFmpeg
 37  : public CDemuxStreamVideo
 38{
 39  CDVDDemuxFFmpeg *m_parent;
 40  AVStream*        m_stream;
 41public:
 42  CDemuxStreamVideoFFmpeg(CDVDDemuxFFmpeg *parent, AVStream* stream)
 43    : m_parent(parent)
 44    , m_stream(stream)
 45  {}
 46  virtual void GetStreamInfo(std::string& strInfo);
 47};
 48
 49
 50class CDemuxStreamAudioFFmpeg
 51  : public CDemuxStreamAudio
 52{
 53  CDVDDemuxFFmpeg *m_parent;
 54  AVStream*        m_stream;
 55public:
 56  CDemuxStreamAudioFFmpeg(CDVDDemuxFFmpeg *parent, AVStream* stream)
 57    : m_parent(parent)
 58    , m_stream(stream)
 59  {}
 60  std::string m_description;
 61
 62  virtual void GetStreamInfo(std::string& strInfo);
 63  virtual void GetStreamName(std::string& strInfo);
 64};
 65
 66class CDemuxStreamSubtitleFFmpeg
 67  : public CDemuxStreamSubtitle
 68{
 69  CDVDDemuxFFmpeg *m_parent;
 70  AVStream*        m_stream;
 71public:
 72  CDemuxStreamSubtitleFFmpeg(CDVDDemuxFFmpeg *parent, AVStream* stream)
 73    : m_parent(parent)
 74    , m_stream(stream)
 75  {}
 76  std::string m_description;
 77
 78  virtual void GetStreamInfo(std::string& strInfo);
 79  virtual void GetStreamName(std::string& strInfo);
 80
 81};
 82
 83#define FFMPEG_FILE_BUFFER_SIZE   32768 // default reading size for ffmpeg
 84#define FFMPEG_DVDNAV_BUFFER_SIZE 2048  // for dvd's
 85
 86class CDVDDemuxFFmpeg : public CDVDDemux
 87{
 88public:
 89  CDVDDemuxFFmpeg();
 90  virtual ~CDVDDemuxFFmpeg();
 91
 92  bool Open(CDVDInputStream* pInput);
 93  void Dispose();
 94  void Reset();
 95  void Flush();
 96  void Abort();
 97  void SetSpeed(int iSpeed);
 98  virtual std::string GetFileName();
 99
100  DemuxPacket* Read();
101
102  bool SeekTime(int time, bool backwords = false, double* startpts = NULL);
103  bool SeekByte(int64_t pos);
104  int GetStreamLength();
105  CDemuxStream* GetStream(int iStreamId);
106  int GetNrOfStreams();
107
108  bool SeekChapter(int chapter, double* startpts = NULL);
109  int GetChapterCount();
110  int GetChapter();
111  void GetChapterName(std::string& strChapterName);
112  virtual void GetStreamCodecName(int iStreamId, CStdString &strName);
113
114  bool Aborted();
115
116  AVFormatContext* m_pFormatContext;
117  CDVDInputStream* m_pInput;
118
119protected:
120  friend class CDemuxStreamAudioFFmpeg;
121  friend class CDemuxStreamVideoFFmpeg;
122  friend class CDemuxStreamSubtitleFFmpeg;
123
124  int ReadFrame(AVPacket *packet);
125  CDemuxStream* AddStream(int iId);
126  void AddStream(int iId, CDemuxStream* stream);
127  CDemuxStream* GetStreamInternal(int iStreamId);
128  void CreateStreams(unsigned int program = UINT_MAX);
129  void DisposeStreams();
130
131  AVDictionary *GetFFMpegOptionsFromURL(const CURL &url);
132  double ConvertTimestamp(int64_t pts, int den, int num);
133  void UpdateCurrentPTS();
134  bool IsProgramChange();
135
136  CCriticalSection m_critSection;
137  std::map<int, CDemuxStream*> m_streams;
138  std::vector<std::map<int, CDemuxStream*>::iterator> m_stream_index;
139
140  AVIOContext* m_ioContext;
141
142  DllAvFormat m_dllAvFormat;
143  DllAvCodec  m_dllAvCodec;
144  DllAvUtil   m_dllAvUtil;
145
146  double   m_iCurrentPts; // used for stream length estimation
147  bool     m_bMatroska;
148  bool     m_bAVI;
149  int      m_speed;
150  unsigned m_program;
151  XbmcThreads::EndTime  m_timeout;
152
153  // Due to limitations of ffmpeg, we only can detect a program change
154  // with a packet. This struct saves the packet for the next read and
155  // signals STREAMCHANGE to player
156  struct
157  {
158    AVPacket pkt;       // packet ffmpeg returned
159    int      result;    // result from av_read_packet
160  }m_pkt;
161};
162