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);
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);
}
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];
/* 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;
/* float sample */
samples[channel][sample] = float(os) / 0x8000;
- cout << samples[channel][sample] << " from s16\n";
-
++channel;
if (channel == _fs->audio_channels()) {
channel = 0;
{
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;
_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 ());
+}
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;
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;
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";
_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") {
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
{
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 ());
signal_changed (AUDIO_SAMPLE_RATE);
}
-void
-FilmState::set_audio_sample_format (AVSampleFormat f)
-{
- _audio_sample_format = f;
- _dirty = true;
-}
-
void
FilmState::set_content_digest (string d)
{
, _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)
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;
return _audio_sample_rate;
}
- AVSampleFormat audio_sample_format () const {
- return _audio_sample_format;
- }
-
std::string content_digest () const {
return _content_digest;
}
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>);
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 */
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");
}
}
#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 ()
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 ();