Support all sample rate available on GUI.

Before we could only use `44100`. Now we can use all available on GUI
for the supported codecs.
This commit is contained in:
Edênis Freindorfer Azevedo 2019-08-06 19:44:30 -03:00 committed by Rafael Kitover
parent aa3ecaf701
commit 738494a232
2 changed files with 11 additions and 3 deletions

View File

@ -106,15 +106,21 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
aenc->sample_fmt = acodec->sample_fmts ? acodec->sample_fmts[0] : AV_SAMPLE_FMT_FLTP; aenc->sample_fmt = acodec->sample_fmts ? acodec->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
aenc->bit_rate = 128000; // mp3 aenc->bit_rate = 128000; // mp3
aenc->sample_rate = sampleRate; aenc->sample_rate = sampleRate;
// this might be useful to check if the codec suports the
// sample rate, but it is not strictly needed for now
bool isSupported = false;
if (acodec->supported_samplerates) if (acodec->supported_samplerates)
{ {
aenc->sample_rate = acodec->supported_samplerates[0];
for (int i = 0; acodec->supported_samplerates[i]; ++i) for (int i = 0; acodec->supported_samplerates[i]; ++i)
{ {
if (acodec->supported_samplerates[i] == 44100) if (acodec->supported_samplerates[i] == sampleRate)
aenc->sample_rate = 44100; {
isSupported = true;
break;
}
} }
} }
if (!isSupported) return MRET_ERR_NOCODEC;
aenc->channels = av_get_channel_layout_nb_channels(aenc->channel_layout); aenc->channels = av_get_channel_layout_nb_channels(aenc->channel_layout);
aenc->channel_layout = AV_CH_LAYOUT_STEREO; aenc->channel_layout = AV_CH_LAYOUT_STEREO;
if (acodec->channel_layouts) if (acodec->channel_layouts)

View File

@ -2340,6 +2340,7 @@ void GameArea::StartVidRecording(const wxString& fname)
{ {
recording::MediaRet ret; recording::MediaRet ret;
vid_rec.SetSampleRate(soundGetSampleRate());
if ((ret = vid_rec.Record(fname.mb_str(), basic_width, basic_height, if ((ret = vid_rec.Record(fname.mb_str(), basic_width, basic_height,
systemColorDepth)) systemColorDepth))
!= recording::MRET_OK) != recording::MRET_OK)
@ -2370,6 +2371,7 @@ void GameArea::StartSoundRecording(const wxString& fname)
{ {
recording::MediaRet ret; recording::MediaRet ret;
snd_rec.SetSampleRate(soundGetSampleRate());
if ((ret = snd_rec.Record(fname.mb_str())) != recording::MRET_OK) if ((ret = snd_rec.Record(fname.mb_str())) != recording::MRET_OK)
wxLogError(_("Unable to begin recording to %s (%s)"), fname.mb_str(), wxLogError(_("Unable to begin recording to %s (%s)"), fname.mb_str(),
media_err(ret)); media_err(ret));