FFmpegKit Linux API 6.0
Loading...
Searching...
No Matches
FFmpegSession.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Taner Sener
3 *
4 * This file is part of FFmpegKit.
5 *
6 * FFmpegKit is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpegKit 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 Lesser General License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General License
17 * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "FFmpegSession.h"
21#include "FFmpegKitConfig.h"
22#include "LogCallback.h"
23#include "StatisticsCallback.h"
24
25extern void addSessionToSessionHistory(const std::shared_ptr<ffmpegkit::Session> session);
26
27std::shared_ptr<ffmpegkit::FFmpegSession> ffmpegkit::FFmpegSession::create(const std::list<std::string>& arguments) {
28 std::shared_ptr<ffmpegkit::FFmpegSession> session = std::static_pointer_cast<ffmpegkit::FFmpegSession>(std::make_shared<ffmpegkit::FFmpegSession::PublicFFmpegSession>(arguments, nullptr, nullptr, nullptr, ffmpegkit::FFmpegKitConfig::getLogRedirectionStrategy()));
30 return session;
31}
32
33std::shared_ptr<ffmpegkit::FFmpegSession> ffmpegkit::FFmpegSession::create(const std::list<std::string>& arguments, FFmpegSessionCompleteCallback completeCallback) {
34 std::shared_ptr<ffmpegkit::FFmpegSession> session = std::static_pointer_cast<ffmpegkit::FFmpegSession>(std::make_shared<ffmpegkit::FFmpegSession::PublicFFmpegSession>(arguments, completeCallback, nullptr, nullptr, ffmpegkit::FFmpegKitConfig::getLogRedirectionStrategy()));
36 return session;
37}
38
39std::shared_ptr<ffmpegkit::FFmpegSession> ffmpegkit::FFmpegSession::create(const std::list<std::string>& arguments, FFmpegSessionCompleteCallback completeCallback, ffmpegkit::LogCallback logCallback, ffmpegkit::StatisticsCallback statisticsCallback) {
40 std::shared_ptr<ffmpegkit::FFmpegSession> session = std::static_pointer_cast<ffmpegkit::FFmpegSession>(std::make_shared<ffmpegkit::FFmpegSession::PublicFFmpegSession>(arguments, completeCallback, logCallback, statisticsCallback, ffmpegkit::FFmpegKitConfig::getLogRedirectionStrategy()));
42 return session;
43}
44
45std::shared_ptr<ffmpegkit::FFmpegSession> ffmpegkit::FFmpegSession::create(const std::list<std::string>& arguments, FFmpegSessionCompleteCallback completeCallback, ffmpegkit::LogCallback logCallback, ffmpegkit::StatisticsCallback statisticsCallback, LogRedirectionStrategy logRedirectionStrategy) {
46 std::shared_ptr<ffmpegkit::FFmpegSession> session = std::static_pointer_cast<ffmpegkit::FFmpegSession>(std::make_shared<ffmpegkit::FFmpegSession::PublicFFmpegSession>(arguments, completeCallback, logCallback, statisticsCallback, logRedirectionStrategy));
48 return session;
49}
50
51struct ffmpegkit::FFmpegSession::PublicFFmpegSession : public ffmpegkit::FFmpegSession {
52 PublicFFmpegSession(const std::list<std::string>& arguments, FFmpegSessionCompleteCallback completeCallback, ffmpegkit::LogCallback logCallback, ffmpegkit::StatisticsCallback statisticsCallback, LogRedirectionStrategy logRedirectionStrategy) :
53 FFmpegSession(arguments, completeCallback, logCallback, statisticsCallback, logRedirectionStrategy) {
54 }
55};
56
58 ffmpegkit::AbstractSession(arguments, logCallback, logRedirectionStrategy), _completeCallback{completeCallback}, _statisticsCallback{statisticsCallback}, _statistics{std::make_shared<std::list<std::shared_ptr<ffmpegkit::Statistics>>>()} {
59}
60
62 return _statisticsCallback;
63}
64
66 return _completeCallback;
67}
68
69std::shared_ptr<std::list<std::shared_ptr<ffmpegkit::Statistics>>> ffmpegkit::FFmpegSession::getAllStatisticsWithTimeout(const int waitTimeout) {
70 this->waitForAsynchronousMessagesInTransmit(waitTimeout);
71
72 if (this->thereAreAsynchronousMessagesInTransmit()) {
73 std::cout << "getAllStatisticsWithTimeout was called to return all statistics but there are still statistics being transmitted for session id " << this->getSessionId() << "." << std::endl;
74 }
75
76 return this->getStatistics();
77}
78
79std::shared_ptr<std::list<std::shared_ptr<ffmpegkit::Statistics>>> ffmpegkit::FFmpegSession::getAllStatistics() {
81}
82
83std::shared_ptr<std::list<std::shared_ptr<ffmpegkit::Statistics>>> ffmpegkit::FFmpegSession::getStatistics() {
84 return _statistics;
85}
86
87std::shared_ptr<ffmpegkit::Statistics> ffmpegkit::FFmpegSession::getLastReceivedStatistics() {
88 if (_statistics->size() > 0) {
89 return _statistics->back();
90 } else {
91 return nullptr;
92 }
93}
94
95void ffmpegkit::FFmpegSession::addStatistics(const std::shared_ptr<ffmpegkit::Statistics> statistics) {
96 _statistics->push_back(statistics);
97}
98
100 return true;
101}
102
104 return false;
105}
106
108 return false;
109}
void addSessionToSessionHistory(const std::shared_ptr< ffmpegkit::Session > session)
static ffmpegkit::LogCallback logCallback
static ffmpegkit::StatisticsCallback statisticsCallback
void addSessionToSessionHistory(const std::shared_ptr< ffmpegkit::Session > session)
static constexpr int DefaultTimeoutForAsynchronousMessagesInTransmit
static LogRedirectionStrategy getLogRedirectionStrategy()
FFmpegSession(const std::list< std::string > &arguments, ffmpegkit::FFmpegSessionCompleteCallback completeCallback, ffmpegkit::LogCallback logCallback, ffmpegkit::StatisticsCallback statisticsCallback, ffmpegkit::LogRedirectionStrategy logRedirectionStrategy)
ffmpegkit::StatisticsCallback getStatisticsCallback()
bool isFFprobe() const override
void addStatistics(const std::shared_ptr< ffmpegkit::Statistics > statistics)
std::shared_ptr< std::list< std::shared_ptr< ffmpegkit::Statistics > > > getAllStatistics()
ffmpegkit::FFmpegSessionCompleteCallback getCompleteCallback()
bool isFFmpeg() const override
std::shared_ptr< ffmpegkit::Statistics > getLastReceivedStatistics()
std::shared_ptr< std::list< std::shared_ptr< ffmpegkit::Statistics > > > getAllStatisticsWithTimeout(const int waitTimeout)
bool isMediaInformation() const override
std::shared_ptr< std::list< std::shared_ptr< ffmpegkit::Statistics > > > getStatistics()
static std::shared_ptr< ffmpegkit::FFmpegSession > create(const std::list< std::string > &arguments)
std::function< void(const std::shared_ptr< ffmpegkit::Statistics > statistics)> StatisticsCallback
std::function< void(const std::shared_ptr< ffmpegkit::Log > log)> LogCallback
Definition LogCallback.h:35
std::function< void(const std::shared_ptr< ffmpegkit::FFmpegSession > session)> FFmpegSessionCompleteCallback