Bump version
[dcpomatic.git] / src / lib / stream.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <sstream>
21 #include "compose.hpp"
22 #include "stream.h"
23 #include "ffmpeg_decoder.h"
24 #include "sndfile_decoder.h"
25
26 #include "i18n.h"
27
28 using std::string;
29 using std::stringstream;
30 using boost::shared_ptr;
31 using boost::optional;
32
33 /** Construct a SubtitleStream from a value returned from to_string().
34  *  @param t String returned from to_string().
35  *  @param v State file version.
36  */
37 SubtitleStream::SubtitleStream (string t, boost::optional<int>)
38 {
39         stringstream n (t);
40         n >> _id;
41
42         size_t const s = t.find (' ');
43         if (s != string::npos) {
44                 _name = t.substr (s + 1);
45         }
46 }
47
48 /** @return A canonical string representation of this stream */
49 string
50 SubtitleStream::to_string () const
51 {
52         return String::compose (N_("%1 %2"), _id, _name);
53 }
54
55 /** Create a SubtitleStream from a value returned from to_string().
56  *  @param t String returned from to_string().
57  *  @param v State file version.
58  */
59 shared_ptr<SubtitleStream>
60 SubtitleStream::create (string t, optional<int> v)
61 {
62         return shared_ptr<SubtitleStream> (new SubtitleStream (t, v));
63 }
64
65 /** Create an AudioStream from a string returned from to_string().
66  *  @param t String returned from to_string().
67  *  @param v State file version.
68  *  @return AudioStream, or 0.
69  */
70 shared_ptr<AudioStream>
71 audio_stream_factory (string t, optional<int> v)
72 {
73         shared_ptr<AudioStream> s;
74
75         s = FFmpegAudioStream::create (t, v);
76         if (!s) {
77                 s = SndfileStream::create (t, v);
78         }
79
80         return s;
81 }
82
83 /** Create a SubtitleStream from a string returned from to_string().
84  *  @param t String returned from to_string().
85  *  @param v State file version.
86  *  @return SubtitleStream, or 0.
87  */
88 shared_ptr<SubtitleStream>
89 subtitle_stream_factory (string t, optional<int> v)
90 {
91         return SubtitleStream::create (t, v);
92 }