Move FFmpegStream classes into their own source files.
authorCarl Hetherington <cth@carlh.net>
Thu, 22 May 2014 13:34:27 +0000 (14:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 22 May 2014 13:34:27 +0000 (14:34 +0100)
19 files changed:
src/lib/ffmpeg.cc
src/lib/ffmpeg_audio_stream.cc [new file with mode: 0644]
src/lib/ffmpeg_audio_stream.h [new file with mode: 0644]
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_examiner.cc
src/lib/ffmpeg_stream.cc [new file with mode: 0644]
src/lib/ffmpeg_stream.h [new file with mode: 0644]
src/lib/ffmpeg_subtitle_stream.cc [new file with mode: 0644]
src/lib/ffmpeg_subtitle_stream.h [new file with mode: 0644]
src/lib/wscript
src/wx/audio_panel.cc
src/wx/subtitle_panel.cc
test/ffmpeg_examiner_test.cc
test/ffmpeg_pts_offset_test.cc
test/frame_rate_test.cc
test/seek_zero_test.cc
test/stream_test.cc

index 316b9614de6f27bb18b26278e2fd21006e65d95f..6f66ebbc069793d6a13250e0cf8f7c2d966bd08f 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
 
     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 <dcp/raw_convert.h>
 #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 (file)
index 0000000..255952b
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+
+    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 <libxml++/libxml++.h>
+#include <libcxml/cxml.h>
+#include <dcp/raw_convert.h>
+#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<int> ("FrameRate");
+       channels = node->number_child<int64_t> ("Channels");
+       first_audio = node->optional_number_child<double> ("FirstAudio");
+}
+
+void
+FFmpegAudioStream::as_xml (xmlpp::Node* root) const
+{
+       FFmpegStream::as_xml (root);
+       root->add_child("FrameRate")->add_child_text (raw_convert<string> (frame_rate));
+       root->add_child("Channels")->add_child_text (raw_convert<string> (channels));
+       if (first_audio) {
+               root->add_child("FirstAudio")->add_child_text (raw_convert<string> (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 (file)
index 0000000..5e455d1
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+
+    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<ContentTime> first_audio;
+
+private:
+       friend class ffmpeg_pts_offset_test;
+
+       /* Constructor for tests */
+       FFmpegAudioStream ()
+               : FFmpegStream ("", 0)
+               , frame_rate (0)
+               , channels (0)
+               , mapping (1)
+       {}
+};
index 6fc8bd7bb0b7beb890cffe71cc8add74c92a2185..a191959fcf6bceb42f94630823fcf1afb1dd45a7 100644 (file)
@@ -24,6 +24,8 @@ extern "C" {
 #include <dcp/raw_convert.h>
 #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<int> ("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<string> (_id));
-}
-
-FFmpegAudioStream::FFmpegAudioStream (cxml::ConstNodePtr node, int version)
-       : FFmpegStream (node)
-       , mapping (node->node_child ("Mapping"), version)
-{
-       frame_rate = node->number_child<int> ("FrameRate");
-       channels = node->number_child<int64_t> ("Channels");
-       first_audio = node->optional_number_child<double> ("FirstAudio");
-}
-
-void
-FFmpegAudioStream::as_xml (xmlpp::Node* root) const
-{
-       FFmpegStream::as_xml (root);
-       root->add_child("FrameRate")->add_child_text (raw_convert<string> (frame_rate));
-       root->add_child("Channels")->add_child_text (raw_convert<string> (channels));
-       if (first_audio) {
-               root->add_child("FirstAudio")->add_child_text (raw_convert<string> (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
 {
index c546d69eb70e9a74107b2c8b3f860a17a3d14b30..6f4980dc7691e619c29bc229c6c9ec235ad9a99c 100644 (file)
@@ -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<std::string> (_id);
-       }
-
-       std::string identifier () const {
-               return boost::lexical_cast<std::string> (_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<ContentTime> 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:
index d251a37446ff96e2e49d514575b7719e53f44b6c..9548eaae9c1a9415d089957befda45233627fba1 100644 (file)
@@ -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"
index 72db9bce1a3cd9abf1b3c2191eb5ed1f0180d10a..a55113f890659729b83dc3891ec5231133dc9af0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
 
     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 (file)
index 0000000..3fac333
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+
+    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 <libavformat/avformat.h>
+}
+#include <libxml++/libxml++.h>
+#include <dcp/raw_convert.h>
+#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<int> ("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<string> (_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 (file)
index 0000000..6bbcd0b
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+
+    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 <boost/lexical_cast.hpp>
+#include <libcxml/cxml.h>
+
+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<std::string> (_id);
+       }
+
+       std::string identifier () const {
+               return boost::lexical_cast<std::string> (_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 (file)
index 0000000..3d8fd4e
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+
+    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 (file)
index 0000000..76c71f0
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+
+    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;
+};
+
index 8f26c53c6e9f6c4456ee4d3123c38b2491d89e0c..d0fe9c8d88a1821a9d6005566c699cf370f7c27c 100644 (file)
@@ -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
index eb95e17abe59db17dca28b496b5025edd22a3a5f..ad1990cdcd2104a9528a2219e882390a0385eafd 100644 (file)
@@ -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"
index b4b5a7b4239e332ba55886cbcdcc3cd329d249df..aa3d3a73547757de1ac2a01537ada723597305f5 100644 (file)
@@ -21,6 +21,7 @@
 #include <wx/spinctrl.h>
 #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"
index d72226a6f68a173ed8e53ae4b788acdf438049e4..26834aafc8d7512b304ae24488d3d013893c8d3b 100644 (file)
@@ -25,6 +25,7 @@
 #include <boost/test/unit_test.hpp>
 #include "lib/ffmpeg_examiner.h"
 #include "lib/ffmpeg_content.h"
+#include "lib/ffmpeg_audio_stream.h"
 #include "test.h"
 
 using boost::shared_ptr;
index 83fe7c7089dd9568bf550b21a2ef0b5f7871a606..94e7223ab394641a3a64940e2dac24a1d0e65804 100644 (file)
@@ -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;
index f2c46396cb36205dffb825ead6fcac1f1cb86bc9..e1d4e43701270b8aeb99b8ec57e4d1fe5993e4db 100644 (file)
@@ -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;
index 77e95c28c11b5d11d42977ec2dfc02b6d26eca27..682fa93555742461f93f556cd714231685c51c23 100644 (file)
@@ -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"
 
index f9dfadad5b7846dd7598dcfd431382af6c4677c5..16ab83baf7747ea933ac1c59d7d115e04e22c591 100644 (file)
@@ -25,6 +25,7 @@
 #include <libxml++/libxml++.h>
 #include <libcxml/cxml.h>
 #include "lib/ffmpeg_content.h"
+#include "lib/ffmpeg_audio_stream.h"
 #include "lib/film.h"
 
 using std::pair;