From 85d343a420c4df1a08663c8afd3bdb73c8dfa985 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 22 May 2014 14:34:27 +0100 Subject: [PATCH] Move FFmpegStream classes into their own source files. --- src/lib/ffmpeg.cc | 3 +- src/lib/ffmpeg_audio_stream.cc | 47 +++++++++++++++++ src/lib/ffmpeg_audio_stream.h | 57 +++++++++++++++++++++ src/lib/ffmpeg_content.cc | 82 +----------------------------- src/lib/ffmpeg_content.h | 83 +------------------------------ src/lib/ffmpeg_decoder.cc | 2 + src/lib/ffmpeg_examiner.cc | 4 +- src/lib/ffmpeg_stream.cc | 71 ++++++++++++++++++++++++++ src/lib/ffmpeg_stream.h | 65 ++++++++++++++++++++++++ src/lib/ffmpeg_subtitle_stream.cc | 36 ++++++++++++++ src/lib/ffmpeg_subtitle_stream.h | 34 +++++++++++++ src/lib/wscript | 3 ++ src/wx/audio_panel.cc | 1 + src/wx/subtitle_panel.cc | 1 + test/ffmpeg_examiner_test.cc | 1 + test/ffmpeg_pts_offset_test.cc | 1 + test/frame_rate_test.cc | 1 + test/seek_zero_test.cc | 1 + test/stream_test.cc | 1 + 19 files changed, 331 insertions(+), 163 deletions(-) create mode 100644 src/lib/ffmpeg_audio_stream.cc create mode 100644 src/lib/ffmpeg_audio_stream.h create mode 100644 src/lib/ffmpeg_stream.cc create mode 100644 src/lib/ffmpeg_stream.h create mode 100644 src/lib/ffmpeg_subtitle_stream.cc create mode 100644 src/lib/ffmpeg_subtitle_stream.h diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index 316b9614d..6f66ebbc0 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ extern "C" { #include #include "ffmpeg.h" #include "ffmpeg_content.h" +#include "ffmpeg_audio_stream.h" #include "exceptions.h" #include "util.h" diff --git a/src/lib/ffmpeg_audio_stream.cc b/src/lib/ffmpeg_audio_stream.cc new file mode 100644 index 000000000..255952b8f --- /dev/null +++ b/src/lib/ffmpeg_audio_stream.cc @@ -0,0 +1,47 @@ +/* + Copyright (C) 2013-2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include +#include "ffmpeg_audio_stream.h" + +using std::string; +using dcp::raw_convert; + +FFmpegAudioStream::FFmpegAudioStream (cxml::ConstNodePtr node, int version) + : FFmpegStream (node) + , mapping (node->node_child ("Mapping"), version) +{ + frame_rate = node->number_child ("FrameRate"); + channels = node->number_child ("Channels"); + first_audio = node->optional_number_child ("FirstAudio"); +} + +void +FFmpegAudioStream::as_xml (xmlpp::Node* root) const +{ + FFmpegStream::as_xml (root); + root->add_child("FrameRate")->add_child_text (raw_convert (frame_rate)); + root->add_child("Channels")->add_child_text (raw_convert (channels)); + if (first_audio) { + root->add_child("FirstAudio")->add_child_text (raw_convert (first_audio.get().get())); + } + mapping.as_xml (root->add_child("Mapping")); +} diff --git a/src/lib/ffmpeg_audio_stream.h b/src/lib/ffmpeg_audio_stream.h new file mode 100644 index 000000000..5e455d18a --- /dev/null +++ b/src/lib/ffmpeg_audio_stream.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2013-2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "ffmpeg_stream.h" +#include "audio_mapping.h" +#include "dcpomatic_time.h" + +class ffmpeg_pts_offset_test; + +class FFmpegAudioStream : public FFmpegStream +{ +public: + FFmpegAudioStream (std::string n, int i, int f, int c) + : FFmpegStream (n, i) + , frame_rate (f) + , channels (c) + , mapping (c) + { + mapping.make_default (); + } + + FFmpegAudioStream (cxml::ConstNodePtr, int); + + void as_xml (xmlpp::Node *) const; + + int frame_rate; + int channels; + AudioMapping mapping; + boost::optional first_audio; + +private: + friend class ffmpeg_pts_offset_test; + + /* Constructor for tests */ + FFmpegAudioStream () + : FFmpegStream ("", 0) + , frame_rate (0) + , channels (0) + , mapping (1) + {} +}; diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 6fc8bd7bb..a191959fc 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -24,6 +24,8 @@ extern "C" { #include #include "ffmpeg_content.h" #include "ffmpeg_examiner.h" +#include "ffmpeg_subtitle_stream.h" +#include "ffmpeg_audio_stream.h" #include "compose.hpp" #include "job.h" #include "util.h" @@ -312,86 +314,6 @@ operator!= (FFmpegStream const & a, FFmpegStream const & b) return a._id != b._id; } -FFmpegStream::FFmpegStream (cxml::ConstNodePtr node) - : name (node->string_child ("Name")) - , _id (node->number_child ("Id")) -{ - -} - -void -FFmpegStream::as_xml (xmlpp::Node* root) const -{ - root->add_child("Name")->add_child_text (name); - root->add_child("Id")->add_child_text (raw_convert (_id)); -} - -FFmpegAudioStream::FFmpegAudioStream (cxml::ConstNodePtr node, int version) - : FFmpegStream (node) - , mapping (node->node_child ("Mapping"), version) -{ - frame_rate = node->number_child ("FrameRate"); - channels = node->number_child ("Channels"); - first_audio = node->optional_number_child ("FirstAudio"); -} - -void -FFmpegAudioStream::as_xml (xmlpp::Node* root) const -{ - FFmpegStream::as_xml (root); - root->add_child("FrameRate")->add_child_text (raw_convert (frame_rate)); - root->add_child("Channels")->add_child_text (raw_convert (channels)); - if (first_audio) { - root->add_child("FirstAudio")->add_child_text (raw_convert (first_audio.get().get())); - } - mapping.as_xml (root->add_child("Mapping")); -} - -bool -FFmpegStream::uses_index (AVFormatContext const * fc, int index) const -{ - size_t i = 0; - while (i < fc->nb_streams) { - if (fc->streams[i]->id == _id) { - return int (i) == index; - } - ++i; - } - - return false; -} - -AVStream * -FFmpegStream::stream (AVFormatContext const * fc) const -{ - size_t i = 0; - while (i < fc->nb_streams) { - if (fc->streams[i]->id == _id) { - return fc->streams[i]; - } - ++i; - } - - assert (false); - return 0; -} - -/** Construct a SubtitleStream from a value returned from to_string(). - * @param t String returned from to_string(). - * @param v State file version. - */ -FFmpegSubtitleStream::FFmpegSubtitleStream (cxml::ConstNodePtr node) - : FFmpegStream (node) -{ - -} - -void -FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const -{ - FFmpegStream::as_xml (root); -} - DCPTime FFmpegContent::full_length () const { diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index c546d69eb..6f4980dc7 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -31,89 +31,10 @@ struct AVFormatContext; struct AVStream; class Filter; +class FFmpegSubtitleStream; +class FFmpegAudioStream; class ffmpeg_pts_offset_test; -class FFmpegStream -{ -public: - FFmpegStream (std::string n, int i) - : name (n) - , _id (i) - {} - - FFmpegStream (cxml::ConstNodePtr); - - void as_xml (xmlpp::Node *) const; - - /** @param c An AVFormatContext. - * @param index A stream index within the AVFormatContext. - * @return true if this FFmpegStream uses the given stream index. - */ - bool uses_index (AVFormatContext const * c, int index) const; - AVStream* stream (AVFormatContext const * c) const; - - std::string technical_summary () const { - return "id " + boost::lexical_cast (_id); - } - - std::string identifier () const { - return boost::lexical_cast (_id); - } - - std::string name; - - friend bool operator== (FFmpegStream const & a, FFmpegStream const & b); - friend bool operator!= (FFmpegStream const & a, FFmpegStream const & b); - -private: - int _id; -}; - -class FFmpegAudioStream : public FFmpegStream -{ -public: - FFmpegAudioStream (std::string n, int i, int f, int c) - : FFmpegStream (n, i) - , frame_rate (f) - , channels (c) - , mapping (c) - { - mapping.make_default (); - } - - FFmpegAudioStream (cxml::ConstNodePtr, int); - - void as_xml (xmlpp::Node *) const; - - int frame_rate; - int channels; - AudioMapping mapping; - boost::optional first_audio; - -private: - friend class ffmpeg_pts_offset_test; - - /* Constructor for tests */ - FFmpegAudioStream () - : FFmpegStream ("", 0) - , frame_rate (0) - , channels (0) - , mapping (1) - {} -}; - -class FFmpegSubtitleStream : public FFmpegStream -{ -public: - FFmpegSubtitleStream (std::string n, int i) - : FFmpegStream (n, i) - {} - - FFmpegSubtitleStream (cxml::ConstNodePtr); - - void as_xml (xmlpp::Node *) const; -}; - class FFmpegContentProperty : public VideoContentProperty { public: diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index d251a3744..9548eaae9 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -38,6 +38,8 @@ extern "C" { #include "util.h" #include "log.h" #include "ffmpeg_decoder.h" +#include "ffmpeg_audio_stream.h" +#include "ffmpeg_subtitle_stream.h" #include "filter_graph.h" #include "audio_buffers.h" #include "ffmpeg_content.h" diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc index 72db9bce1..a55113f89 100644 --- a/src/lib/ffmpeg_examiner.cc +++ b/src/lib/ffmpeg_examiner.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,6 +23,8 @@ extern "C" { } #include "ffmpeg_examiner.h" #include "ffmpeg_content.h" +#include "ffmpeg_audio_stream.h" +#include "ffmpeg_subtitle_stream.h" #include "i18n.h" diff --git a/src/lib/ffmpeg_stream.cc b/src/lib/ffmpeg_stream.cc new file mode 100644 index 000000000..3fac33327 --- /dev/null +++ b/src/lib/ffmpeg_stream.cc @@ -0,0 +1,71 @@ +/* + Copyright (C) 2013-2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +extern "C" { +#include +} +#include +#include +#include "ffmpeg_stream.h" + +using std::string; +using dcp::raw_convert; + +FFmpegStream::FFmpegStream (cxml::ConstNodePtr node) + : name (node->string_child ("Name")) + , _id (node->number_child ("Id")) +{ + +} + +void +FFmpegStream::as_xml (xmlpp::Node* root) const +{ + root->add_child("Name")->add_child_text (name); + root->add_child("Id")->add_child_text (raw_convert (_id)); +} + +bool +FFmpegStream::uses_index (AVFormatContext const * fc, int index) const +{ + size_t i = 0; + while (i < fc->nb_streams) { + if (fc->streams[i]->id == _id) { + return int (i) == index; + } + ++i; + } + + return false; +} + +AVStream * +FFmpegStream::stream (AVFormatContext const * fc) const +{ + size_t i = 0; + while (i < fc->nb_streams) { + if (fc->streams[i]->id == _id) { + return fc->streams[i]; + } + ++i; + } + + assert (false); + return 0; +} diff --git a/src/lib/ffmpeg_stream.h b/src/lib/ffmpeg_stream.h new file mode 100644 index 000000000..6bbcd0b01 --- /dev/null +++ b/src/lib/ffmpeg_stream.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2013-2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef DCPOMATIC_FFMPEG_STREAM_H +#define DCPOMATIC_FFMPEG_STREAM_H + +#include +#include + +struct AVFormatContext; +struct AVStream; + +class FFmpegStream +{ +public: + FFmpegStream (std::string n, int i) + : name (n) + , _id (i) + {} + + FFmpegStream (cxml::ConstNodePtr); + + void as_xml (xmlpp::Node *) const; + + /** @param c An AVFormatContext. + * @param index A stream index within the AVFormatContext. + * @return true if this FFmpegStream uses the given stream index. + */ + bool uses_index (AVFormatContext const * c, int index) const; + AVStream* stream (AVFormatContext const * c) const; + + std::string technical_summary () const { + return "id " + boost::lexical_cast (_id); + } + + std::string identifier () const { + return boost::lexical_cast (_id); + } + + std::string name; + + friend bool operator== (FFmpegStream const & a, FFmpegStream const & b); + friend bool operator!= (FFmpegStream const & a, FFmpegStream const & b); + +private: + int _id; +}; + +#endif diff --git a/src/lib/ffmpeg_subtitle_stream.cc b/src/lib/ffmpeg_subtitle_stream.cc new file mode 100644 index 000000000..3d8fd4e83 --- /dev/null +++ b/src/lib/ffmpeg_subtitle_stream.cc @@ -0,0 +1,36 @@ +/* + Copyright (C) 2013-2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "ffmpeg_subtitle_stream.h" + +/** Construct a SubtitleStream from a value returned from to_string(). + * @param t String returned from to_string(). + * @param v State file version. + */ +FFmpegSubtitleStream::FFmpegSubtitleStream (cxml::ConstNodePtr node) + : FFmpegStream (node) +{ + +} + +void +FFmpegSubtitleStream::as_xml (xmlpp::Node* root) const +{ + FFmpegStream::as_xml (root); +} diff --git a/src/lib/ffmpeg_subtitle_stream.h b/src/lib/ffmpeg_subtitle_stream.h new file mode 100644 index 000000000..76c71f016 --- /dev/null +++ b/src/lib/ffmpeg_subtitle_stream.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2013-2014 Carl Hetherington + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "dcpomatic_time.h" +#include "ffmpeg_stream.h" + +class FFmpegSubtitleStream : public FFmpegStream +{ +public: + FFmpegSubtitleStream (std::string n, int i) + : FFmpegStream (n, i) + {} + + FFmpegSubtitleStream (cxml::ConstNodePtr); + + void as_xml (xmlpp::Node *) const; +}; + diff --git a/src/lib/wscript b/src/lib/wscript index 8f26c53c6..d0fe9c8d8 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -26,9 +26,12 @@ sources = """ file_group.cc filter_graph.cc ffmpeg.cc + ffmpeg_audio_stream.cc ffmpeg_content.cc ffmpeg_decoder.cc ffmpeg_examiner.cc + ffmpeg_stream.cc + ffmpeg_subtitle_stream.cc film.cc filter.cc frame_rate_change.cc diff --git a/src/wx/audio_panel.cc b/src/wx/audio_panel.cc index eb95e17ab..ad1990cdc 100644 --- a/src/wx/audio_panel.cc +++ b/src/wx/audio_panel.cc @@ -22,6 +22,7 @@ #include "lib/config.h" #include "lib/sound_processor.h" #include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_audio_stream.h" #include "audio_dialog.h" #include "audio_panel.h" #include "audio_mapping_view.h" diff --git a/src/wx/subtitle_panel.cc b/src/wx/subtitle_panel.cc index b4b5a7b42..aa3d3a735 100644 --- a/src/wx/subtitle_panel.cc +++ b/src/wx/subtitle_panel.cc @@ -21,6 +21,7 @@ #include #include "lib/ffmpeg_content.h" #include "lib/subrip_content.h" +#include "lib/ffmpeg_subtitle_stream.h" #include "subtitle_panel.h" #include "film_editor.h" #include "wx_util.h" diff --git a/test/ffmpeg_examiner_test.cc b/test/ffmpeg_examiner_test.cc index d72226a6f..26834aafc 100644 --- a/test/ffmpeg_examiner_test.cc +++ b/test/ffmpeg_examiner_test.cc @@ -25,6 +25,7 @@ #include #include "lib/ffmpeg_examiner.h" #include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_audio_stream.h" #include "test.h" using boost::shared_ptr; diff --git a/test/ffmpeg_pts_offset_test.cc b/test/ffmpeg_pts_offset_test.cc index 83fe7c708..94e7223ab 100644 --- a/test/ffmpeg_pts_offset_test.cc +++ b/test/ffmpeg_pts_offset_test.cc @@ -25,6 +25,7 @@ #include "lib/film.h" #include "lib/ffmpeg_decoder.h" #include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_audio_stream.h" #include "test.h" using boost::shared_ptr; diff --git a/test/frame_rate_test.cc b/test/frame_rate_test.cc index f2c46396c..e1d4e4370 100644 --- a/test/frame_rate_test.cc +++ b/test/frame_rate_test.cc @@ -27,6 +27,7 @@ #include "lib/config.h" #include "lib/ffmpeg_content.h" #include "lib/playlist.h" +#include "lib/ffmpeg_audio_stream.h" #include "test.h" using boost::shared_ptr; diff --git a/test/seek_zero_test.cc b/test/seek_zero_test.cc index 77e95c28c..682fa9355 100644 --- a/test/seek_zero_test.cc +++ b/test/seek_zero_test.cc @@ -28,6 +28,7 @@ #include "lib/ratio.h" #include "lib/dcp_content_type.h" #include "lib/ffmpeg_decoder.h" +#include "lib/ffmpeg_audio_stream.h" #include "lib/content_video.h" #include "test.h" diff --git a/test/stream_test.cc b/test/stream_test.cc index f9dfadad5..16ab83baf 100644 --- a/test/stream_test.cc +++ b/test/stream_test.cc @@ -25,6 +25,7 @@ #include #include #include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_audio_stream.h" #include "lib/film.h" using std::pair; -- 2.30.2