#include <sstream>
#include "compose.hpp"
#include "stream.h"
+#include "ffmpeg_decoder.h"
+#include "external_audio_decoder.h"
-using namespace std;
+using std::string;
+using std::stringstream;
+using boost::shared_ptr;
+using boost::optional;
-AudioStream::AudioStream (string t)
+/** 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 ("%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 = ExternalAudioStream::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);
}