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.
throw CreateFileError (m);
}
+ f << "version " << state_version << "\n";
+
/* User stuff */
f << "name " << _name << "\n";
f << "use_dci_name " << _use_dci_name << "\n";
_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);
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;
} 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);
} 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");
} 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;
}
#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);
#define DVDOMATIC_STREAM_H
#include <stdint.h>
+#include <boost/optional.hpp>
extern "C" {
#include <libavutil/audioconvert.h>
}
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)
, _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 {