-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathdemuxing.cpp
More file actions
141 lines (119 loc) · 4.34 KB
/
Copy pathdemuxing.cpp
File metadata and controls
141 lines (119 loc) · 4.34 KB
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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <libspdl/core/demuxing.h>
#include "libspdl/common/tracing.h"
#include "libspdl/core/detail/ffmpeg/demuxer.h"
#include "libspdl/core/detail/ffmpeg/logging.h"
namespace spdl::core {
namespace detail {
namespace {
DataInterfacePtr get_interface(
const std::string_view src,
const SourceAdaptorPtr& adaptor,
const std::optional<DemuxConfig>& dmx_cfg,
const std::optional<std::string>& name) {
if (!adaptor) {
thread_local auto p = std::make_shared<SourceAdaptor>();
return p->get_interface(src, dmx_cfg.value_or(DemuxConfig{}), name);
}
return adaptor->get_interface(src, dmx_cfg.value_or(DemuxConfig{}), name);
}
DataInterfacePtr get_in_memory_interface(
const std::string_view data,
const std::optional<DemuxConfig>& dmx_cfg,
const std::optional<std::string>& name) {
thread_local SourceAdaptorPtr adaptor = std::make_shared<BytesAdaptor>();
return adaptor->get_interface(data, dmx_cfg.value_or(DemuxConfig{}), name);
}
} // namespace
} // namespace detail
////////////////////////////////////////////////////////////////////////////////
// StreamingDemuxer
////////////////////////////////////////////////////////////////////////////////
StreamingDemuxer::StreamingDemuxer(
detail::DemuxerImpl* p,
const std::set<int>& stream_indices,
int num_packets,
double duration)
: gen_(p->streaming_demux(stream_indices, num_packets, duration)) {}
bool StreamingDemuxer::done() {
return !bool(gen_);
}
std::map<int, AnyPackets> StreamingDemuxer::next() {
return gen_();
}
////////////////////////////////////////////////////////////////////////////////
// Demuxer
////////////////////////////////////////////////////////////////////////////////
Demuxer::Demuxer(DataInterfacePtr di)
: pImpl_(new detail::DemuxerImpl(std::move(di))) {}
Demuxer::~Demuxer() {
if (pImpl_) {
delete pImpl_;
}
}
bool Demuxer::has_audio() const {
return pImpl_->has_audio();
}
template <MediaType media>
Codec<media> Demuxer::get_default_codec() const {
return pImpl_->get_default_codec<media>();
}
template Codec<MediaType::Audio> Demuxer::get_default_codec<MediaType::Audio>()
const;
template Codec<MediaType::Video> Demuxer::get_default_codec<MediaType::Video>()
const;
template Codec<MediaType::Image> Demuxer::get_default_codec<MediaType::Image>()
const;
template <MediaType media>
int Demuxer::get_default_stream_index() const {
return pImpl_->get_default_stream_index<media>();
}
template int Demuxer::get_default_stream_index<MediaType::Audio>() const;
template int Demuxer::get_default_stream_index<MediaType::Video>() const;
template int Demuxer::get_default_stream_index<MediaType::Image>() const;
template <MediaType media>
PacketsPtr<media> Demuxer::demux_window(
const std::optional<TimeWindow>& window,
const std::optional<std::string>& bsf) {
return pImpl_->demux_window<media>(window, bsf);
}
template PacketsPtr<MediaType::Audio> Demuxer::demux_window(
const std::optional<TimeWindow>& window,
const std::optional<std::string>& bsf);
template PacketsPtr<MediaType::Video> Demuxer::demux_window(
const std::optional<TimeWindow>& window,
const std::optional<std::string>& bsf);
template PacketsPtr<MediaType::Image> Demuxer::demux_window(
const std::optional<TimeWindow>& window,
const std::optional<std::string>& bsf);
StreamingDemuxerPtr Demuxer::streaming_demux(
const std::set<int>& indices,
int num_packets,
double duration) {
return std::make_unique<StreamingDemuxer>(
pImpl_, indices, num_packets, duration);
}
DemuxerPtr make_demuxer(
const std::string& src,
const SourceAdaptorPtr& adaptor,
const std::optional<DemuxConfig>& dmx_cfg,
const std::optional<std::string>& name) {
TRACE_EVENT("demuxing", "make_demuxer");
return std::make_unique<Demuxer>(
detail::get_interface(src, adaptor, dmx_cfg, name));
}
DemuxerPtr make_demuxer(
const std::string_view data,
const std::optional<DemuxConfig>& dmx_cfg,
const std::optional<std::string>& name) {
TRACE_EVENT("demuxing", "make_demuxer");
return std::make_unique<Demuxer>(
detail::get_in_memory_interface(data, dmx_cfg, name));
}
} // namespace spdl::core