Try a bit of backwards compatibility in state file.
[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
24 using namespace std;
25 using boost::optional;
26
27 AudioStream::AudioStream (string t, optional<int> version)
28 {
29         stringstream n (t);
30         
31         int name_index = 3;
32         if (!version) {
33                 name_index = 2;
34                 int channels;
35                 n >> _id >> channels;
36                 _channel_layout = av_get_default_channel_layout (channels);
37                 _sample_rate = 0;
38         } else {
39                 /* Current (marked version 1) */
40                 n >> _id >> _sample_rate >> _channel_layout;
41         }
42
43         for (int i = 0; i < name_index; ++i) {
44                 size_t const s = t.find (' ');
45                 if (s != string::npos) {
46                         t = t.substr (s + 1);
47                 }
48         }
49
50         _name = t;
51 }
52
53 string
54 AudioStream::to_string () const
55 {
56         return String::compose ("%1 %2 %3 %4", _id, _sample_rate, _channel_layout, _name);
57 }
58
59 SubtitleStream::SubtitleStream (string t)
60 {
61         stringstream n (t);
62         n >> _id;
63
64         size_t const s = t.find (' ');
65         if (s != string::npos) {
66                 _name = t.substr (s + 1);
67         }
68 }
69
70 string
71 SubtitleStream::to_string () const
72 {
73         return String::compose ("%1 %2", _id, _name);
74 }