Bump version
[dcpomatic.git] / src / lib / stream.cc
index 9d10813f77a52f7aeea6085fa784d7479fbad0cf..bfe7b5eb4b85054ad76def09d195714458ab7c6f 100644 (file)
 #include <sstream>
 #include "compose.hpp"
 #include "stream.h"
+#include "ffmpeg_decoder.h"
+#include "sndfile_decoder.h"
 
-using namespace std;
+#include "i18n.h"
 
-AudioStream::AudioStream (string t)
+using std::string;
+using std::stringstream;
+using boost::shared_ptr;
+using boost::optional;
+
+/** Construct a SubtitleStream from a value returned from to_string().
+ *  @param t String returned from to_string().
+ *  @param v State file version.
+ */
+SubtitleStream::SubtitleStream (string t, boost::optional<int>)
 {
        stringstream n (t);
-       n >> _id >> _sample_rate >> _channel_layout;
+       n >> _id;
 
-       for (int i = 0; i < 2; ++i) {
-               size_t const s = t.find (' ');
-               if (s != string::npos) {
-                       t = t.substr (s + 1);
-               }
+       size_t const s = t.find (' ');
+       if (s != string::npos) {
+               _name = t.substr (s + 1);
        }
-
-       _name = t;
 }
 
+/** @return A canonical string representation of this stream */
 string
-AudioStream::to_string () const
+SubtitleStream::to_string () const
 {
-       return String::compose ("%1 %2 %3 %4", _id, _sample_rate, _channel_layout, _name);
+       return String::compose (N_("%1 %2"), _id, _name);
 }
 
-SubtitleStream::SubtitleStream (string t)
+/** Create a SubtitleStream from a value returned from to_string().
+ *  @param t String returned from to_string().
+ *  @param v State file version.
+ */
+shared_ptr<SubtitleStream>
+SubtitleStream::create (string t, optional<int> v)
 {
-       stringstream n (t);
-       n >> _id;
+       return shared_ptr<SubtitleStream> (new SubtitleStream (t, v));
+}
 
-       size_t const s = t.find (' ');
-       if (s != string::npos) {
-               _name = t.substr (s + 1);
+/** Create an AudioStream from a string returned from to_string().
+ *  @param t String returned from to_string().
+ *  @param v State file version.
+ *  @return AudioStream, or 0.
+ */
+shared_ptr<AudioStream>
+audio_stream_factory (string t, optional<int> v)
+{
+       shared_ptr<AudioStream> s;
+
+       s = FFmpegAudioStream::create (t, v);
+       if (!s) {
+               s = SndfileStream::create (t, v);
        }
+
+       return s;
 }
 
-string
-SubtitleStream::to_string () const
+/** Create a SubtitleStream from a string returned from to_string().
+ *  @param t String returned from to_string().
+ *  @param v State file version.
+ *  @return SubtitleStream, or 0.
+ */
+shared_ptr<SubtitleStream>
+subtitle_stream_factory (string t, optional<int> v)
 {
-       return String::compose ("%1 %2", _id, _name);
+       return SubtitleStream::create (t, v);
 }