Fix wav audio recording
Always use `av_wrte_trailer()` even for audio recordings, because an invalid wav file was generated otherwise.
This commit is contained in:
parent
f915ec5972
commit
2ad7dd1a79
|
@ -339,34 +339,34 @@ recording::MediaRet recording::MediaRecorder::Record(const char *fname, int widt
|
||||||
ret = setup_common(fname);
|
ret = setup_common(fname);
|
||||||
if (ret != MRET_OK)
|
if (ret != MRET_OK)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop(false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// video stream
|
// video stream
|
||||||
ret = setup_video_stream_info(width, height, depth);
|
ret = setup_video_stream_info(width, height, depth);
|
||||||
if (ret != MRET_OK)
|
if (ret != MRET_OK)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop(false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = setup_video_stream(width, height);
|
ret = setup_video_stream(width, height);
|
||||||
if (ret != MRET_OK)
|
if (ret != MRET_OK)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop(false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// audio stream
|
// audio stream
|
||||||
ret = setup_audio_stream();
|
ret = setup_audio_stream();
|
||||||
if (ret != MRET_OK)
|
if (ret != MRET_OK)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop(false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// last details
|
// last details
|
||||||
ret = finish_setup(fname);
|
ret = finish_setup(fname);
|
||||||
if (ret != MRET_OK)
|
if (ret != MRET_OK)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop(false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return MRET_OK;
|
return MRET_OK;
|
||||||
|
@ -409,12 +409,12 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint8_t *vid)
|
||||||
return MRET_OK;
|
return MRET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void recording::MediaRecorder::Stop()
|
void recording::MediaRecorder::Stop(bool initSuccess)
|
||||||
{
|
{
|
||||||
if (oc)
|
if (oc)
|
||||||
{
|
{
|
||||||
// write the trailer; must be called before av_codec_close()
|
// write the trailer; must be called before av_codec_close()
|
||||||
if (!audioOnlyRecording)
|
if (initSuccess) // only call av_write_trailer() if initialization went ok
|
||||||
av_write_trailer(oc);
|
av_write_trailer(oc);
|
||||||
}
|
}
|
||||||
isRecording = false;
|
isRecording = false;
|
||||||
|
@ -521,21 +521,21 @@ recording::MediaRet recording::MediaRecorder::Record(const char *fname)
|
||||||
ret = setup_common(fname);
|
ret = setup_common(fname);
|
||||||
if (ret != MRET_OK)
|
if (ret != MRET_OK)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop(false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// audio stream
|
// audio stream
|
||||||
ret = setup_audio_stream();
|
ret = setup_audio_stream();
|
||||||
if (ret != MRET_OK)
|
if (ret != MRET_OK)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop(false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// last details
|
// last details
|
||||||
ret = finish_setup(fname);
|
ret = finish_setup(fname);
|
||||||
if (ret != MRET_OK)
|
if (ret != MRET_OK)
|
||||||
{
|
{
|
||||||
Stop();
|
Stop(false);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return MRET_OK;
|
return MRET_OK;
|
||||||
|
|
|
@ -67,7 +67,7 @@ class MediaRecorder
|
||||||
// start audio only
|
// start audio only
|
||||||
MediaRet Record(const char *fname);
|
MediaRet Record(const char *fname);
|
||||||
// stop both
|
// stop both
|
||||||
void Stop();
|
void Stop(bool initSuccess = true);
|
||||||
bool IsRecording()
|
bool IsRecording()
|
||||||
{
|
{
|
||||||
return isRecording;
|
return isRecording;
|
||||||
|
|
Loading…
Reference in New Issue