diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-11-14 23:39:00 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-11-14 23:39:00 +0000 |
| commit | febb57f618c0f932fca1f9f6400145b5ce1785d1 (patch) | |
| tree | 3c30739e888245345b71ef25db7e8fd41ea2090f /src/lib | |
| parent | 65e7ad9b9512816a3313db7e817ed2466d84d644 (diff) | |
Try a bit of backwards compatibility in state file.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/film.cc | 32 | ||||
| -rw-r--r-- | src/lib/film.h | 4 | ||||
| -rw-r--r-- | src/lib/stream.cc | 18 | ||||
| -rw-r--r-- | src/lib/stream.h | 8 |
4 files changed, 50 insertions, 12 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc index f45a92447..846356212 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -71,6 +71,8 @@ using boost::ends_with; using boost::starts_with; using boost::optional; +int const Film::state_version = 1; + /** Construct a Film object in a given directory, reading any metadata * file that exists in that directory. An exception will be thrown if * must_exist is true and the specified directory does not exist. @@ -397,6 +399,8 @@ Film::write_metadata () const throw CreateFileError (m); } + f << "version " << state_version << "\n"; + /* User stuff */ f << "name " << _name << "\n"; f << "use_dci_name " << _use_dci_name << "\n"; @@ -476,6 +480,9 @@ Film::read_metadata () _thumbs.clear (); _audio_streams.clear (); _subtitle_streams.clear (); + + boost::optional<int> version; + boost::optional<int> audio_sample_rate; ifstream f (file ("metadata").c_str()); multimap<string, string> kv = read_key_value (f); @@ -483,6 +490,12 @@ Film::read_metadata () string const k = i->first; string const v = i->second; + if (k == "version") { + version = atoi (v.c_str()); + } else if (k == "audio_sample_rate") { + audio_sample_rate = atoi (v.c_str()); + } + /* User-specified stuff */ if (k == "name") { _name = v; @@ -515,10 +528,9 @@ Film::read_metadata () } else if (k == "use_content_audio") { _use_content_audio = (v == "1"); } else if (k == "selected_audio_stream") { - AudioStream st (v); /* check for -1 for backwards compatibility */ - if (st.id() != -1) { - _audio_stream = AudioStream (v); + if (atoi(v.c_str()) != -1) { + _audio_stream = AudioStream (v, version); } } else if (k == "external_audio") { _external_audio.push_back (v); @@ -529,10 +541,9 @@ Film::read_metadata () } else if (k == "still_duration") { _still_duration = atoi (v.c_str ()); } else if (k == "selected_subtitle_stream") { - SubtitleStream st (v); /* check for -1 for backwards compatibility */ - if (st.id() != -1) { - _subtitle_stream = st; + if (atoi(v.c_str()) != -1) { + _subtitle_stream = SubtitleStream (v); } } else if (k == "with_subtitles") { _with_subtitles = (v == "1"); @@ -575,13 +586,20 @@ Film::read_metadata () } else if (k == "content_digest") { _content_digest = v; } else if (k == "audio_stream") { - _audio_streams.push_back (AudioStream (v)); + _audio_streams.push_back (AudioStream (v, version)); } else if (k == "subtitle_stream") { _subtitle_streams.push_back (SubtitleStream (v)); } else if (k == "frames_per_second") { _frames_per_second = atof (v.c_str ()); } } + + if (!version && audio_sample_rate) { + /* version < 1 didn't specify sample rate in the audio streams, so fill it in here */ + for (vector<AudioStream>::iterator i = _audio_streams.begin(); i != _audio_streams.end(); ++i) { + i->set_sample_rate (audio_sample_rate.get()); + } + } _dirty = false; } diff --git a/src/lib/film.h b/src/lib/film.h index 0e2a4e5ef..37eb13d25 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -369,7 +369,9 @@ public: /** Emitted when some property has changed */ mutable boost::signals2::signal<void (Property)> Changed; - + + static int const state_version; + private: /** Log to write to */ diff --git a/src/lib/stream.cc b/src/lib/stream.cc index fd7eccfbf..5bc184eb9 100644 --- a/src/lib/stream.cc +++ b/src/lib/stream.cc @@ -22,13 +22,25 @@ #include "stream.h" using namespace std; +using boost::optional; -AudioStream::AudioStream (string t) +AudioStream::AudioStream (string t, optional<int> version) { stringstream n (t); - n >> _id >> _sample_rate >> _channel_layout; + + int name_index = 3; + if (!version) { + name_index = 2; + int channels; + n >> _id >> channels; + _channel_layout = av_get_default_channel_layout (channels); + _sample_rate = 0; + } else { + /* Current (marked version 1) */ + n >> _id >> _sample_rate >> _channel_layout; + } - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < name_index; ++i) { size_t const s = t.find (' '); if (s != string::npos) { t = t.substr (s + 1); diff --git a/src/lib/stream.h b/src/lib/stream.h index d6c4ca382..760befa02 100644 --- a/src/lib/stream.h +++ b/src/lib/stream.h @@ -21,6 +21,7 @@ #define DVDOMATIC_STREAM_H #include <stdint.h> +#include <boost/optional.hpp> extern "C" { #include <libavutil/audioconvert.h> } @@ -55,7 +56,7 @@ protected: struct AudioStream : public Stream { public: - AudioStream (std::string t); + AudioStream (std::string t, boost::optional<int> v); AudioStream (std::string n, int id, int r, int64_t l) : Stream (n, id) @@ -63,6 +64,11 @@ public: , _channel_layout (l) {} + /** Only used for state file version < 1 compatibility */ + void set_sample_rate (int r) { + _sample_rate = r; + } + std::string to_string () const; int channels () const { |
