BMediaEncoder: Init/Release code cleanup.

This commit is contained in:
Dario Casalinuovo 2015-12-02 15:27:35 +01:00
parent 106539c239
commit 9bc60a8bc0

View File

@ -55,8 +55,7 @@ BMediaEncoder::BMediaEncoder(const media_codec_info *mci)
BMediaEncoder::~BMediaEncoder() BMediaEncoder::~BMediaEncoder()
{ {
CALLED(); CALLED();
gPluginManager.DestroyEncoder(fEncoder); ReleaseEncoder();
fEncoder = NULL;
} }
@ -72,33 +71,26 @@ BMediaEncoder::SetTo(const media_format *output_format)
{ {
CALLED(); CALLED();
gPluginManager.DestroyEncoder(fEncoder);
fEncoder = NULL;
fInitStatus = B_OK;
status_t err = B_ERROR; status_t err = B_ERROR;
if (output_format != NULL) { ReleaseEncoder();
media_format format = *output_format;
status_t err = gPluginManager.CreateEncoder(&fEncoder, format); if (output_format == NULL)
if (err != B_OK) return fInitStatus;
goto fail;
media_format format = *output_format;
err = gPluginManager.CreateEncoder(&fEncoder, format);
if (fEncoder != NULL && err == B_OK) {
err = _AttachToEncoder(); err = _AttachToEncoder();
if (err != B_OK) if (err == B_OK) {
goto fail; err = SetFormat(NULL, &format);
if (err == B_OK) {
err = SetFormat(NULL, &format); fInitStatus = B_OK;
if (err != B_OK) return B_OK;
goto fail; }
}
return B_OK;
} }
ReleaseEncoder();
fail:
fInitStatus = err; fInitStatus = err;
gPluginManager.DestroyEncoder(fEncoder);
fEncoder = NULL;
fInitStatus = B_NO_INIT;
return err; return err;
} }
@ -108,24 +100,18 @@ BMediaEncoder::SetTo(const media_codec_info *mci)
{ {
CALLED(); CALLED();
gPluginManager.DestroyEncoder(fEncoder); ReleaseEncoder();
fEncoder = NULL;
status_t err = gPluginManager.CreateEncoder(&fEncoder, mci, 0); status_t err = gPluginManager.CreateEncoder(&fEncoder, mci, 0);
if (err < B_OK) if (fEncoder != NULL && err == B_OK) {
goto fail; err = _AttachToEncoder();
if (err == B_OK) {
fInitStatus = B_OK;
return B_OK;
}
}
err = _AttachToEncoder(); ReleaseEncoder();
if (err < B_OK) fInitStatus = err;
goto fail;
fInitStatus = B_OK;
return B_OK;
fail:
gPluginManager.DestroyEncoder(fEncoder);
fEncoder = NULL;
fInitStatus = B_NO_INIT;
return err; return err;
} }
@ -232,7 +218,12 @@ BMediaEncoder::Init()
void void
BMediaEncoder::ReleaseEncoder() BMediaEncoder::ReleaseEncoder()
{ {
UNIMPLEMENTED(); CALLED();
if (fEncoder != NULL) {
gPluginManager.DestroyEncoder(fEncoder);
fEncoder = NULL;
}
fInitStatus = B_NO_INIT;
} }