diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-20 17:03:32 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-20 17:03:32 +0100 |
| commit | d23ced341f50f47759e75260d706c06c0cb74046 (patch) | |
| tree | a029685c2aff69c9cbce8839f2cdcf42d4b08748 /src/lib | |
| parent | 476af651fc34d7c6394fea0e39d351392b4e46d3 (diff) | |
Don't cache sample format, fix up various things.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/decoder.cc | 26 | ||||
| -rw-r--r-- | src/lib/decoder.h | 1 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.h | 1 | ||||
| -rw-r--r-- | src/lib/film_state.cc | 18 | ||||
| -rw-r--r-- | src/lib/film_state.h | 9 | ||||
| -rw-r--r-- | src/lib/j2k_wav_encoder.cc | 8 | ||||
| -rw-r--r-- | src/lib/util.cc | 29 | ||||
| -rw-r--r-- | src/lib/util.h | 2 |
8 files changed, 20 insertions, 74 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index ec046fcaf..16d815a07 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -90,7 +90,7 @@ Decoder::~Decoder () void Decoder::process_begin () { - _delay_in_bytes = _fs->audio_delay() * _fs->audio_sample_rate() * _fs->audio_channels() * _fs->bytes_per_sample() / 1000; + _delay_in_bytes = _fs->audio_delay() * _fs->audio_sample_rate() * _fs->audio_channels() * bytes_per_audio_sample() / 1000; delete _delay_line; _delay_line = new DelayLine (_delay_in_bytes); @@ -104,7 +104,7 @@ Decoder::process_end () if (_delay_in_bytes < 0) { uint8_t remainder[-_delay_in_bytes]; _delay_line->get_remaining (remainder); - _audio_frames_processed += _delay_in_bytes / (_fs->audio_channels() * _fs->bytes_per_sample()); + _audio_frames_processed += _delay_in_bytes / (_fs->audio_channels() * bytes_per_audio_sample()); emit_audio (remainder, _delay_in_bytes); } @@ -122,7 +122,7 @@ Decoder::process_end () s << "Adding " << audio_short_by_frames << " frames of silence to the end."; _log->log (s.str ()); - int64_t bytes = audio_short_by_frames * _fs->audio_channels() * _fs->bytes_per_sample(); + int64_t bytes = audio_short_by_frames * _fs->audio_channels() * bytes_per_audio_sample(); int64_t const silence_size = 64 * 1024; uint8_t silence[silence_size]; @@ -193,13 +193,13 @@ Decoder::emit_audio (uint8_t* data, int size) /* Deinterleave and convert to float */ float* samples[_fs->audio_channels()]; - int const total_samples = size / _fs->bytes_per_sample(); + int const total_samples = size / bytes_per_audio_sample(); int const frames = total_samples / _fs->audio_channels(); for (int i = 0; i < _fs->audio_channels(); ++i) { samples[i] = new float[frames]; } - switch (_fs->audio_sample_format()) { + switch (audio_sample_format()) { case AV_SAMPLE_FMT_S16: { uint8_t* p = data; @@ -213,8 +213,6 @@ Decoder::emit_audio (uint8_t* data, int size) /* float sample */ samples[channel][sample] = float(os) / 0x8000; - cout << samples[channel][sample] << " from s16\n"; - ++channel; if (channel == _fs->audio_channels()) { channel = 0; @@ -230,11 +228,8 @@ Decoder::emit_audio (uint8_t* data, int size) { float* p = reinterpret_cast<float*> (data); for (int i = 0; i < _fs->audio_channels(); ++i) { - for (int j = 0; j < frames; ++j) { - samples[i][j] = *p++; - cout << samples[i][j] << " from float.\n"; - ++p; - } + memcpy (samples[i], p, frames * sizeof(float)); + p += frames; } } break; @@ -460,3 +455,10 @@ Decoder::process_subtitle (shared_ptr<TimedSubtitle> s) _timed_subtitle->subtitle()->set_position (Position (p.x - _fs->crop().left, p.y - _fs->crop().top)); } } + + +int +Decoder::bytes_per_audio_sample () const +{ + return av_get_bytes_per_sample (audio_sample_format ()); +} diff --git a/src/lib/decoder.h b/src/lib/decoder.h index 88dd90f0c..14e602ace 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -138,6 +138,7 @@ protected: private: void setup_video_filters (); void emit_audio (uint8_t* data, int size); + int bytes_per_audio_sample () const; /** last video frame to be processed */ int _video_frame; diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 9abc7f49a..0d256b37e 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -65,6 +65,7 @@ public: AVSampleFormat audio_sample_format () const; int64_t audio_channel_layout () const; bool has_subtitles () const; + int bytes_per_audio_sample () const; std::vector<Stream> audio_streams () const; std::vector<Stream> subtitle_streams () const; diff --git a/src/lib/film_state.cc b/src/lib/film_state.cc index f2d83e4e2..46359677c 100644 --- a/src/lib/film_state.cc +++ b/src/lib/film_state.cc @@ -115,7 +115,6 @@ FilmState::write_metadata () const f << "length " << _length << "\n"; f << "audio_channels " << _audio_channels << "\n"; f << "audio_sample_rate " << _audio_sample_rate << "\n"; - f << "audio_sample_format " << audio_sample_format_to_string (_audio_sample_format) << "\n"; f << "content_digest " << _content_digest << "\n"; f << "has_subtitles " << _has_subtitles << "\n"; @@ -224,8 +223,6 @@ FilmState::read_metadata () _audio_channels = atoi (v.c_str ()); } else if (k == "audio_sample_rate") { _audio_sample_rate = atoi (v.c_str ()); - } else if (k == "audio_sample_format") { - _audio_sample_format = audio_sample_format_from_string (v); } else if (k == "content_digest") { _content_digest = v; } else if (k == "has_subtitles") { @@ -354,13 +351,6 @@ FilmState::content_type () const return VIDEO; } -/** @return Number of bytes per sample of a single channel */ -int -FilmState::bytes_per_sample () const -{ - return av_get_bytes_per_sample (_audio_sample_format); -} - int FilmState::target_sample_rate () const { @@ -543,7 +533,6 @@ FilmState::set_content (string c) set_frames_per_second (d->frames_per_second ()); set_audio_channels (d->audio_channels ()); set_audio_sample_rate (d->audio_sample_rate ()); - set_audio_sample_format (d->audio_sample_format ()); set_has_subtitles (d->has_subtitles ()); set_audio_streams (d->audio_streams ()); set_subtitle_streams (d->subtitle_streams ()); @@ -796,13 +785,6 @@ FilmState::set_audio_sample_rate (int r) } void -FilmState::set_audio_sample_format (AVSampleFormat f) -{ - _audio_sample_format = f; - _dirty = true; -} - -void FilmState::set_content_digest (string d) { _content_digest = d; diff --git a/src/lib/film_state.h b/src/lib/film_state.h index 2a00c844a..40908693f 100644 --- a/src/lib/film_state.h +++ b/src/lib/film_state.h @@ -72,7 +72,6 @@ public: , _length (0) , _audio_channels (0) , _audio_sample_rate (0) - , _audio_sample_format (AV_SAMPLE_FMT_NONE) , _has_subtitles (false) , _frames_per_second (0) , _dirty (false) @@ -90,7 +89,6 @@ public: std::string thumb_base (int) const; int thumb_frame (int) const; - int bytes_per_sample () const; int target_sample_rate () const; void write_metadata () const; @@ -272,10 +270,6 @@ public: return _audio_sample_rate; } - AVSampleFormat audio_sample_format () const { - return _audio_sample_format; - } - std::string content_digest () const { return _content_digest; } @@ -335,7 +329,6 @@ public: void set_length (int); void set_audio_channels (int); void set_audio_sample_rate (int); - void set_audio_sample_format (AVSampleFormat); void set_content_digest (std::string); void set_has_subtitles (bool); void set_audio_streams (std::vector<Stream>); @@ -422,8 +415,6 @@ private: int _audio_channels; /** Sample rate of the source audio, in Hz */ int _audio_sample_rate; - /** Format of the audio samples */ - AVSampleFormat _audio_sample_format; /** MD5 digest of our content file */ std::string _content_digest; /** true if the source has subtitles */ diff --git a/src/lib/j2k_wav_encoder.cc b/src/lib/j2k_wav_encoder.cc index 58f8a101f..7697a5e78 100644 --- a/src/lib/j2k_wav_encoder.cc +++ b/src/lib/j2k_wav_encoder.cc @@ -351,16 +351,16 @@ J2KWAVEncoder::process_audio (float** data, int frames) if (_swr_context) { /* Compute the resampled frames count and add 32 for luck */ - int const resampled_frames = ceil (frames * _fs->target_sample_rate() / _fs->audio_sample_rate()) + 32; + int const max_resampled_frames = ceil (frames * _fs->target_sample_rate() / _fs->audio_sample_rate()) + 32; /* Make a buffer to put the result in */ for (int i = 0; i < _fs->audio_channels(); ++i) { - resampled[i] = new float[resampled_frames]; + resampled[i] = new float[max_resampled_frames]; } /* Resample audio */ - int out_frames = swr_convert (_swr_context, (uint8_t **) resampled, resampled_frames, (uint8_t const **) data, frames); - if (out_frames < 0) { + int const resampled_frames = swr_convert (_swr_context, (uint8_t **) resampled, max_resampled_frames, (uint8_t const **) data, frames); + if (resampled_frames < 0) { throw EncodeError ("could not run sample-rate converter"); } diff --git a/src/lib/util.cc b/src/lib/util.cc index 47a86da9e..3f5200ead 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -189,35 +189,6 @@ stacktrace (ostream& out, int levels) } #endif -/** @param s Sample format. - * @return String representation. - */ -string -audio_sample_format_to_string (AVSampleFormat s) -{ - /* Our sample format handling is not exactly complete */ - - switch (s) { - case AV_SAMPLE_FMT_S16: - return "S16"; - default: - assert (false); - } -} - -/** @param s String representation of a sample format, as returned from audio_sample_format_to_string(). - * @return Sample format. - */ -AVSampleFormat -audio_sample_format_from_string (string s) -{ - if (s == "S16") { - return AV_SAMPLE_FMT_S16; - } - - assert (false); -} - /** @return Version of vobcopy that is on the path (and hence that we will use) */ static string vobcopy_version () diff --git a/src/lib/util.h b/src/lib/util.h index c2706a594..f2087b3f0 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -46,8 +46,6 @@ class Scaler; extern std::string seconds_to_hms (int); extern std::string seconds_to_approximate_hms (int); extern void stacktrace (std::ostream &, int); -extern std::string audio_sample_format_to_string (AVSampleFormat); -extern AVSampleFormat audio_sample_format_from_string (std::string); extern std::string dependency_version_summary (); extern double seconds (struct timeval); extern void dvdomatic_setup (); |
