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