30#include <libavcodec/avcodec.h>
31#include <libavformat/avformat.h>
34#include <vdr/player.h>
57 std::string subString =
m_path.substr(0,
m_path.find_last_of(
"/"));
58 m_subFolder = subString.substr(subString.find_last_of(
"/") +1, std::string::npos);
60 std::string folderString =
m_path.substr(0, subString.find_last_of(
"/"));
61 m_folder = folderString.substr(folderString.find_last_of(
"/") +1, std::string::npos);
83 return (strcasestr(source,
".M3U") && !strcasestr(source,
".M3U8"));
93 : cPlayer(pmAudioVideo),
95 m_pAudio(m_pDevice->Audio())
97 m_pSource = (
char *) malloc(1 + strlen(url));
179 std::ifstream inputFile;
183 inputFile.open(playlist);
184 if (!inputFile.good()) {
185 LOGERROR(
"mediaplayer: %s: open PL %s failed", __FUNCTION__, playlist);
189 while (!inputFile.eof()) {
191 getline(inputFile, s);
192 if (s.size() && s.compare(0, 1,
"#")) {
218 for (
int i = 0; i < index ; i++) {
234#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(59,0,100)
237 const AVCodec *videoCodec;
240 int audioStreamIdx = 0;
242 int jumpStreamIdx = 0;
248 AVFormatContext *format = avformat_alloc_context();
249 if (avformat_open_input(&format, url, NULL, NULL) != 0) {
250 LOGERROR(
"mediaplayer: %s: Could not open file '%s'", __FUNCTION__, url);
254 av_dump_format(format, -1, url, 0);
256 if (avformat_find_stream_info(format, NULL) < 0) {
257 LOGERROR(
"mediaplayer: %s: Could not retrieve stream info from file '%s'", __FUNCTION__, url);
261 for (
unsigned int i = 0; i < format->nb_streams; i++) {
262 if (format->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
264 format->streams[i]->codecpar, format->streams[i]->time_base);
265 audioStreamIdx = jumpStreamIdx = i;
270 videoStreamIdx = av_find_best_stream(format, AVMEDIA_TYPE_VIDEO, -1, -1, &videoCodec, 0);
272 if (videoStreamIdx < 0) {
273 LOGDEBUG2(
L_MEDIA,
"mediaplayer: %s: stream does not seem to contain video", __FUNCTION__);
276 format->streams[videoStreamIdx]->codecpar,
277 format->streams[videoStreamIdx]->time_base);
278 jumpStreamIdx = videoStreamIdx;
282 startTime = format->start_time / AV_TIME_BASE;
284 AVPacket *packet =
nullptr;
287 packet = av_packet_alloc();
289 LOGFATAL(
"mediaplayer: %s: out of memory", __FUNCTION__);
293 err = av_read_frame(format, packet);
295 LOGDEBUG2(
L_MEDIA,
"mediaplayer: %s: av_read_frame error: %s", __FUNCTION__,
298 av_packet_free(&packet);
303 if (audioStreamIdx == packet->stream_index) {
305 usleep(packet->duration * AV_TIME_BASE *
306 av_q2d(format->streams[audioStreamIdx]->time_base));
309 av_packet_free(&packet);
312 }
else if (videoStreamIdx == packet->stream_index) {
314 usleep(packet->duration * AV_TIME_BASE *
315 av_q2d(format->streams[videoStreamIdx]->time_base));
320 av_packet_free(&packet);
328 av_seek_frame(format, format->streams[jumpStreamIdx]->index,
330 av_q2d(format->streams[jumpStreamIdx]->time_base)), 0);
335 av_packet_free(&packet);
347 av_packet_free(&packet);
352 avformat_close_input(&format);
353 avformat_free_context(format);
402 m_pOsd = Skins.Current()->DisplayReplay(
false);
Audio and alsa module header file.
std::string OsdItemString(void)
Compose a full-path-string for the OSD entry.
std::string GetPath(void)
void SetNextEntry(cPlaylistEntry *entry)
cPlaylistEntry * GetNextEntry(void)
cPlaylistEntry(std::string)
Builds the playlist entry from a file name.
int64_t GetHardwareOutputPtsMs(void)
Get the hardware output PTS in milliseconds.
virtual eOSState ProcessKey(eKeys)
Handle a key event.
cSoftHdControl(const char *, cSoftHdDevice *)
Create a new control interface and corresponding player.
static cSoftHdControl * Control()
cSoftHdDevice * m_pDevice
cSkinDisplayReplay * m_pOsd
void ShowProgress()
Open the replay OSD.
static cSoftHdPlayer * m_pPlayer
static cSoftHdControl * m_pControl
virtual void Hide(void)
Close the replay OSD.
virtual ~cSoftHdControl()
int PlayAudioPkts(AVPacket *)
Play an audio packet.
virtual void Clear(void)
Clears all video and audio data from the device.
void SetAudioCodec(enum AVCodecID, AVCodecParameters *, AVRational)
Open an audio codec.
virtual void Play(void)
Sets the device into play mode (after a previous trick mode, or pause)
int PlayVideoPkts(AVPacket *)
Play a video packet.
virtual void Freeze(void)
Puts the device into "freeze frame" mode.
void SetVideoCodec(enum AVCodecID, AVCodecParameters *, AVRational)
Open a video codec.
std::atomic< bool > m_stopped
virtual void Action(void)
Main thread action which invokes replay start.
void JumpSec(int seconds)
std::atomic< int > m_jumpSec
cPlaylistEntry * m_pFirstEntry
std::atomic< bool > m_random
void ReadPlaylist(const char *)
Read the playlist file.
const char * GetSource(void)
cPlaylistEntry * m_pCurrentEntry
virtual void Activate(bool On)
Start player thread.
std::atomic< bool > m_paused
cPlaylistEntry * GetCurrentPlaylistEntry(void)
cSoftHdDevice * m_pDevice
cSoftHdPlayer(const char *, cSoftHdDevice *)
Create a new player for a file or playlist.
void SetEntry(int)
Set the current entry to play.
void Play(const char *)
Play a file.
Logger class header file.
#define LOGFATAL
Logger macros.
Misc function header file.
Device class header file.