summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ab_transcoder.cc2
-rw-r--r--src/lib/decoder.h11
-rw-r--r--src/lib/encoder.h2
-rw-r--r--src/lib/ffmpeg_decoder.cc51
-rw-r--r--src/lib/ffmpeg_decoder.h11
-rw-r--r--src/lib/film_state.cc42
-rw-r--r--src/lib/film_state.h40
-rw-r--r--src/lib/imagemagick_encoder.h2
-rw-r--r--src/lib/j2k_still_encoder.h2
-rw-r--r--src/lib/j2k_wav_encoder.cc2
-rw-r--r--src/lib/j2k_wav_encoder.h2
-rw-r--r--src/lib/stream.cc33
-rw-r--r--src/lib/stream.h57
-rw-r--r--src/lib/transcoder.cc2
14 files changed, 148 insertions, 111 deletions
diff --git a/src/lib/ab_transcoder.cc b/src/lib/ab_transcoder.cc
index 54153ec76..08938a282 100644
--- a/src/lib/ab_transcoder.cc
+++ b/src/lib/ab_transcoder.cc
@@ -104,7 +104,7 @@ ABTranscoder::process_video (shared_ptr<Image> yuv, int frame, shared_ptr<Subtit
void
ABTranscoder::go ()
{
- _encoder->process_begin (_da->audio_channel_layout(), _da->audio_sample_format());
+ _encoder->process_begin (_da->audio_channel_layout());
_da->process_begin ();
_db->process_begin ();
diff --git a/src/lib/decoder.h b/src/lib/decoder.h
index 85b256f5b..2285cf4f9 100644
--- a/src/lib/decoder.h
+++ b/src/lib/decoder.h
@@ -81,17 +81,14 @@ public:
return _video_frame;
}
- virtual std::vector<Stream> audio_streams () const {
- return std::vector<Stream> ();
+ virtual std::vector<AudioStream> audio_streams () const {
+ return std::vector<AudioStream> ();
}
- virtual std::vector<Stream> subtitle_streams () const {
- return std::vector<Stream> ();
+ virtual std::vector<SubtitleStream> subtitle_streams () const {
+ return std::vector<SubtitleStream> ();
}
- virtual void set_audio_stream (Stream s) {}
- virtual void set_subtitle_stream (Stream s) {}
-
/** Emitted when a video frame is ready.
* First parameter is the frame.
* Second parameter is its index within the content.
diff --git a/src/lib/encoder.h b/src/lib/encoder.h
index 3317d30d1..561e41901 100644
--- a/src/lib/encoder.h
+++ b/src/lib/encoder.h
@@ -55,7 +55,7 @@ public:
Encoder (boost::shared_ptr<const FilmState> s, boost::shared_ptr<const Options> o, Log* l);
/** Called to indicate that a processing run is about to begin */
- virtual void process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format) = 0;
+ virtual void process_begin (int64_t audio_channel_layout) = 0;
/** Called with a frame of video.
* @param i Video frame image.
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index 4b0594add..d93b023c3 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -109,43 +109,30 @@ FFmpegDecoder::setup_general ()
/* Find video, audio and subtitle streams and choose the first of each */
for (uint32_t i = 0; i < _format_context->nb_streams; ++i) {
- if (_format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ AVStream* s = _format_context->streams[i];
+ if (s->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
_video_stream = i;
- } else if (_format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
+ } else if (s->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
if (_audio_stream == -1) {
_audio_stream = i;
}
- _audio_streams.push_back (Stream (stream_name (_format_context->streams[i]), i));
- } else if (_format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
+ _audio_streams.push_back (AudioStream (stream_name (s), i, s->codec->channels));
+ } else if (s->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) {
if (_subtitle_stream == -1) {
_subtitle_stream = i;
}
- _subtitle_streams.push_back (Stream (stream_name (_format_context->streams[i]), i));
+ _subtitle_streams.push_back (SubtitleStream (stream_name (s), i));
}
}
/* Now override audio and subtitle streams with those from the Film, if it has any */
- if (_fs->audio_stream() != -1) {
- vector<Stream>::iterator i = _audio_streams.begin ();
- while (i != _audio_streams.end() && i->id != _fs->audio_stream()) {
- ++i;
- }
-
- if (i != _audio_streams.end()) {
- _audio_stream = _fs->audio_stream ();
- }
+ if (_fs->audio_stream_index() != -1) {
+ _audio_stream = _fs->audio_stream_decoder_id ();
}
- if (_fs->subtitle_stream() != -1) {
- vector<Stream>::iterator i = _subtitle_streams.begin ();
- while (i != _subtitle_streams.end() && i->id != _fs->subtitle_stream()) {
- ++i;
- }
-
- if (i != _subtitle_streams.end()) {
- _subtitle_stream = _fs->subtitle_stream ();
- }
+ if (_fs->subtitle_stream_index() != -1) {
+ _subtitle_stream = _fs->subtitle_stream_decoder_id ();
}
if (_video_stream < 0) {
@@ -394,32 +381,18 @@ FFmpegDecoder::has_subtitles () const
return (_subtitle_stream != -1);
}
-vector<Stream>
+vector<AudioStream>
FFmpegDecoder::audio_streams () const
{
return _audio_streams;
}
-vector<Stream>
+vector<SubtitleStream>
FFmpegDecoder::subtitle_streams () const
{
return _subtitle_streams;
}
-void
-FFmpegDecoder::set_audio_stream (int s)
-{
- _audio_stream = s;
- setup_audio ();
-}
-
-void
-FFmpegDecoder::set_subtitle_stream (int s)
-{
- _subtitle_stream = s;
- setup_subtitle ();
-}
-
string
FFmpegDecoder::stream_name (AVStream* s) const
{
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index 0d256b37e..339afbaef 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -67,11 +67,8 @@ public:
bool has_subtitles () const;
int bytes_per_audio_sample () const;
- std::vector<Stream> audio_streams () const;
- std::vector<Stream> subtitle_streams () const;
-
- void set_audio_stream (int id);
- void set_subtitle_stream (int id);
+ std::vector<AudioStream> audio_streams () const;
+ std::vector<SubtitleStream> subtitle_streams () const;
private:
@@ -97,8 +94,8 @@ private:
int _subtitle_stream; ///< may be < 0 if there is no subtitle
AVFrame* _frame;
- std::vector<Stream> _audio_streams;
- std::vector<Stream> _subtitle_streams;
+ std::vector<AudioStream> _audio_streams;
+ std::vector<SubtitleStream> _subtitle_streams;
AVCodecContext* _video_codec_context;
AVCodec* _video_codec;
diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc
index 46359677c..8dd8309a8 100644
--- a/src/lib/film_state.cc
+++ b/src/lib/film_state.cc
@@ -113,16 +113,15 @@ FilmState::write_metadata () const
f << "width " << _size.width << "\n";
f << "height " << _size.height << "\n";
f << "length " << _length << "\n";
- f << "audio_channels " << _audio_channels << "\n";
f << "audio_sample_rate " << _audio_sample_rate << "\n";
f << "content_digest " << _content_digest << "\n";
f << "has_subtitles " << _has_subtitles << "\n";
- for (vector<Stream>::const_iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) {
+ for (vector<AudioStream>::const_iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) {
f << "audio_stream " << i->to_string () << "\n";
}
- for (vector<Stream>::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
+ for (vector<SubtitleStream>::const_iterator i = _subtitle_streams.begin(); i != _subtitle_streams.end(); ++i) {
f << "subtitle_stream " << i->to_string () << "\n";
}
@@ -219,8 +218,6 @@ FilmState::read_metadata ()
_size.height = atoi (v.c_str ());
} else if (k == "length") {
_length = atof (v.c_str ());
- } else if (k == "audio_channels") {
- _audio_channels = atoi (v.c_str ());
} else if (k == "audio_sample_rate") {
_audio_sample_rate = atoi (v.c_str ());
} else if (k == "content_digest") {
@@ -228,9 +225,9 @@ FilmState::read_metadata ()
} else if (k == "has_subtitles") {
_has_subtitles = (v == "1");
} else if (k == "audio_stream") {
- _audio_streams.push_back (Stream (v));
+ _audio_streams.push_back (AudioStream (v));
} else if (k == "subtitle_stream") {
- _subtitle_streams.push_back (Stream (v));
+ _subtitle_streams.push_back (SubtitleStream (v));
} else if (k == "frames_per_second") {
_frames_per_second = atof (v.c_str ());
}
@@ -424,7 +421,7 @@ FilmState::dci_name () const
d << "_";
}
- switch (_audio_channels) {
+ switch (_audio_streams[_audio_stream].channels()) {
case 1:
d << "10_";
break;
@@ -531,13 +528,12 @@ FilmState::set_content (string c)
set_size (d->native_size ());
set_length (d->length_in_frames ());
set_frames_per_second (d->frames_per_second ());
- set_audio_channels (d->audio_channels ());
set_audio_sample_rate (d->audio_sample_rate ());
set_has_subtitles (d->has_subtitles ());
set_audio_streams (d->audio_streams ());
set_subtitle_streams (d->subtitle_streams ());
- set_audio_stream (audio_streams().empty() ? -1 : audio_streams().front().id);
- set_subtitle_stream (subtitle_streams().empty() ? -1 : subtitle_streams().front().id);
+ set_audio_stream (audio_streams().empty() ? -1 : 0);
+ set_subtitle_stream (subtitle_streams().empty() ? -1 : 0);
set_content_digest (md5_digest (content_path ()));
_content = c;
@@ -771,13 +767,6 @@ FilmState::set_length (int l)
}
void
-FilmState::set_audio_channels (int c)
-{
- _audio_channels = c;
- signal_changed (AUDIO_CHANNELS);
-}
-
-void
FilmState::set_audio_sample_rate (int r)
{
_audio_sample_rate = r;
@@ -799,14 +788,14 @@ FilmState::set_has_subtitles (bool s)
}
void
-FilmState::set_audio_streams (vector<Stream> s)
+FilmState::set_audio_streams (vector<AudioStream> s)
{
_audio_streams = s;
_dirty = true;
}
void
-FilmState::set_subtitle_streams (vector<Stream> s)
+FilmState::set_subtitle_streams (vector<SubtitleStream> s)
{
_subtitle_streams = s;
_dirty = true;
@@ -831,3 +820,16 @@ FilmState::state_copy () const
{
return shared_ptr<FilmState> (new FilmState (*this));
}
+
+int
+FilmState::audio_channels () const
+{
+ if (_audio_stream == -1) {
+ return 0;
+ }
+
+ return _audio_streams[_audio_stream].channels ();
+}
+
+
+
diff --git a/src/lib/film_state.h b/src/lib/film_state.h
index 40908693f..46374a17d 100644
--- a/src/lib/film_state.h
+++ b/src/lib/film_state.h
@@ -70,7 +70,6 @@ public:
, _subtitle_offset (0)
, _subtitle_scale (1)
, _length (0)
- , _audio_channels (0)
, _audio_sample_rate (0)
, _has_subtitles (false)
, _frames_per_second (0)
@@ -106,6 +105,8 @@ public:
return _dirty;
}
+ int audio_channels () const;
+
enum Property {
NONE,
NAME,
@@ -131,7 +132,6 @@ public:
THUMBS,
SIZE,
LENGTH,
- AUDIO_CHANNELS,
AUDIO_SAMPLE_RATE,
HAS_SUBTITLES,
AUDIO_STREAMS,
@@ -190,10 +190,15 @@ public:
return _dcp_ab;
}
- int audio_stream () const {
+ int audio_stream_index () const {
return _audio_stream;
}
+ int audio_stream_decoder_id () const {
+ assert (_audio_stream < int (_audio_streams.size()));
+ return _audio_streams[_audio_stream].id ();
+ }
+
float audio_gain () const {
return _audio_gain;
}
@@ -206,10 +211,15 @@ public:
return _still_duration;
}
- int subtitle_stream () const {
+ int subtitle_stream_index () const {
return _subtitle_stream;
}
+ int subtitle_stream_decoder_id () const {
+ assert (_subtitle_stream < int (_subtitle_streams.size()));
+ return _subtitle_streams[_subtitle_stream].id ();
+ }
+
bool with_subtitles () const {
return _with_subtitles;
}
@@ -262,10 +272,6 @@ public:
return _length;
}
- int audio_channels () const {
- return _audio_channels;
- }
-
int audio_sample_rate () const {
return _audio_sample_rate;
}
@@ -278,11 +284,11 @@ public:
return _has_subtitles;
}
- std::vector<Stream> audio_streams () const {
+ std::vector<AudioStream> audio_streams () const {
return _audio_streams;
}
- std::vector<Stream> subtitle_streams () const {
+ std::vector<SubtitleStream> subtitle_streams () const {
return _subtitle_streams;
}
@@ -331,8 +337,8 @@ public:
void set_audio_sample_rate (int);
void set_content_digest (std::string);
void set_has_subtitles (bool);
- void set_audio_streams (std::vector<Stream>);
- void set_subtitle_streams (std::vector<Stream>);
+ void set_audio_streams (std::vector<AudioStream>);
+ void set_subtitle_streams (std::vector<SubtitleStream>);
void set_frames_per_second (float);
/** Emitted when some property has changed */
@@ -375,7 +381,7 @@ private:
has the specified filters and post-processing.
*/
bool _dcp_ab;
- /** The decoder's stream ID to use for audio, or -1 if there is none */
+ /** An index into our _audio_streams vector for the stream to use for audio, or -1 if there is none */
int _audio_stream;
/** Gain to apply to audio in dB */
float _audio_gain;
@@ -383,7 +389,7 @@ private:
int _audio_delay;
/** Duration to make still-sourced films (in seconds) */
int _still_duration;
- /** The decoder's stream ID to use for subtitles, or -1 if there are none */
+ /** An index into our _subtitle_streams vector for the stream to use for subtitles, or -1 if there is none */
int _subtitle_stream;
/** True if subtitles should be shown for this film */
bool _with_subtitles;
@@ -411,8 +417,6 @@ private:
Size _size;
/** Length of the source in frames */
int _length;
- /** Number of audio channels */
- int _audio_channels;
/** Sample rate of the source audio, in Hz */
int _audio_sample_rate;
/** MD5 digest of our content file */
@@ -420,9 +424,9 @@ private:
/** true if the source has subtitles */
bool _has_subtitles;
/** the audio streams that the source has */
- std::vector<Stream> _audio_streams;
+ std::vector<AudioStream> _audio_streams;
/** the subtitle streams that the source has */
- std::vector<Stream> _subtitle_streams;
+ std::vector<SubtitleStream> _subtitle_streams;
/** Frames per second of the source */
float _frames_per_second;
diff --git a/src/lib/imagemagick_encoder.h b/src/lib/imagemagick_encoder.h
index 06f1723b1..29767ed03 100644
--- a/src/lib/imagemagick_encoder.h
+++ b/src/lib/imagemagick_encoder.h
@@ -36,7 +36,7 @@ class ImageMagickEncoder : public Encoder
public:
ImageMagickEncoder (boost::shared_ptr<const FilmState> s, boost::shared_ptr<const Options> o, Log* l);
- void process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format) {}
+ void process_begin (int64_t audio_channel_layout) {}
void process_video (boost::shared_ptr<Image>, int, boost::shared_ptr<Subtitle>);
void process_audio (boost::shared_ptr<const AudioBuffers>) {}
void process_end () {}
diff --git a/src/lib/j2k_still_encoder.h b/src/lib/j2k_still_encoder.h
index 7e7719321..928afe372 100644
--- a/src/lib/j2k_still_encoder.h
+++ b/src/lib/j2k_still_encoder.h
@@ -36,7 +36,7 @@ class J2KStillEncoder : public Encoder
public:
J2KStillEncoder (boost::shared_ptr<const FilmState>, boost::shared_ptr<const Options>, Log *);
- void process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format) {}
+ void process_begin (int64_t audio_channel_layout) {}
void process_video (boost::shared_ptr<Image>, int, boost::shared_ptr<Subtitle>);
void process_audio (boost::shared_ptr<const AudioBuffers>) {}
void process_end () {}
diff --git a/src/lib/j2k_wav_encoder.cc b/src/lib/j2k_wav_encoder.cc
index a83c283d7..8747bb7ad 100644
--- a/src/lib/j2k_wav_encoder.cc
+++ b/src/lib/j2k_wav_encoder.cc
@@ -216,7 +216,7 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server)
}
void
-J2KWAVEncoder::process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format)
+J2KWAVEncoder::process_begin (int64_t audio_channel_layout)
{
if (_fs->audio_sample_rate() != _fs->target_sample_rate()) {
#ifdef HAVE_SWRESAMPLE
diff --git a/src/lib/j2k_wav_encoder.h b/src/lib/j2k_wav_encoder.h
index 2c18a5730..6733221de 100644
--- a/src/lib/j2k_wav_encoder.h
+++ b/src/lib/j2k_wav_encoder.h
@@ -50,7 +50,7 @@ public:
J2KWAVEncoder (boost::shared_ptr<const FilmState>, boost::shared_ptr<const Options>, Log *);
~J2KWAVEncoder ();
- void process_begin (int64_t audio_channel_layout, AVSampleFormat audio_sample_format);
+ void process_begin (int64_t audio_channel_layout);
void process_video (boost::shared_ptr<Image>, int, boost::shared_ptr<Subtitle>);
void process_audio (boost::shared_ptr<const AudioBuffers>);
void process_end ();
diff --git a/src/lib/stream.cc b/src/lib/stream.cc
index e40738990..d1c2b5a9e 100644
--- a/src/lib/stream.cc
+++ b/src/lib/stream.cc
@@ -23,19 +23,40 @@
using namespace std;
-Stream::Stream (string t)
+AudioStream::AudioStream (string t)
{
stringstream n (t);
- n >> id;
-
+ n >> _id >> _channels;
+
+ for (int i = 0; i < 2; ++i) {
+ size_t const s = t.find (' ');
+ if (s != string::npos) {
+ t = t.substr (s + 1);
+ }
+ }
+
+ _name = t;
+}
+
+string
+AudioStream::to_string () const
+{
+ return String::compose ("%1 %2 %3", _id, _channels, _name);
+}
+
+SubtitleStream::SubtitleStream (string t)
+{
+ stringstream n (t);
+ n >> _id;
+
size_t const s = t.find (' ');
if (s != string::npos) {
- name = t.substr (s + 1);
+ _name = t.substr (s + 1);
}
}
string
-Stream::to_string () const
+SubtitleStream::to_string () const
{
- return String::compose ("%1 %2", id, name);
+ return String::compose ("%1 %2", _id, _name);
}
diff --git a/src/lib/stream.h b/src/lib/stream.h
index 764c03d79..2db63c620 100644
--- a/src/lib/stream.h
+++ b/src/lib/stream.h
@@ -20,20 +20,63 @@
#ifndef DVDOMATIC_STREAM_H
#define DVDOMATIC_STREAM_H
-struct Stream
+class Stream
{
public:
- Stream (std::string t);
+ Stream ()
+ : _id (-1)
+ {}
Stream (std::string n, int i)
- : name (n)
- , id (i)
+ : _name (n)
+ , _id (i)
{}
- std::string to_string () const;
+ virtual std::string to_string () const = 0;
- std::string name;
- int id;
+ std::string name () const {
+ return _name;
+ }
+
+ int id () const {
+ return _id;
+ }
+
+protected:
+ std::string _name;
+ int _id;
+};
+
+struct AudioStream : public Stream
+{
+public:
+ AudioStream (std::string t);
+
+ AudioStream (std::string n, int i, int c)
+ : Stream (n, i)
+ , _channels (c)
+ {}
+
+ std::string to_string () const;
+
+ int channels () const {
+ return _channels;
+ }
+
+private:
+ int _channels;
+};
+
+class SubtitleStream : public Stream
+{
+public:
+ SubtitleStream (std::string t);
+
+ SubtitleStream (std::string n, int i)
+ : Stream (n, i)
+ {}
+
+ std::string to_string () const;
};
#endif
diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc
index b74d09174..a809e55d2 100644
--- a/src/lib/transcoder.cc
+++ b/src/lib/transcoder.cc
@@ -57,7 +57,7 @@ Transcoder::Transcoder (shared_ptr<const FilmState> s, shared_ptr<const Options>
void
Transcoder::go ()
{
- _encoder->process_begin (_decoder->audio_channel_layout(), _decoder->audio_sample_format());
+ _encoder->process_begin (_decoder->audio_channel_layout());
try {
_decoder->go ();
} catch (...) {