libeplayer/container_ffmpeg: switch to ffmpeg 2.0 API

This commit is contained in:
martii
2014-04-03 18:10:03 +02:00
parent d2c6b63cc2
commit 212a414a5e
4 changed files with 31 additions and 36 deletions

View File

@@ -435,7 +435,7 @@ static void FFMPEGThread(Context_t * context)
swr = NULL; swr = NULL;
} }
if (decoded_frame) { if (decoded_frame) {
avcodec_free_frame(&decoded_frame); av_frame_free(&decoded_frame);
decoded_frame = NULL; decoded_frame = NULL;
} }
context->output->Command(context, OUTPUT_CLEAR, NULL); context->output->Command(context, OUTPUT_CLEAR, NULL);
@@ -455,7 +455,7 @@ static void FFMPEGThread(Context_t * context)
exit(1); exit(1);
} }
} else } else
avcodec_get_frame_defaults(decoded_frame); av_frame_unref(decoded_frame);
int len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &packet); int len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &packet);
if (len < 0) { if (len < 0) {
@@ -635,7 +635,7 @@ static void FFMPEGThread(Context_t * context)
if (swr) if (swr)
swr_free(&swr); swr_free(&swr);
if (decoded_frame) if (decoded_frame)
avcodec_free_frame(&decoded_frame); av_frame_free(&decoded_frame);
if (context->playback) if (context->playback)
context->playback->abortPlayback = 1; context->playback->abortPlayback = 1;

View File

@@ -125,8 +125,7 @@ static int prepareClipPlay(int uNoOfChannels, int uSampleRate,
memcpy(lpcm_prv, clpcm_prv, sizeof(lpcm_prv)); memcpy(lpcm_prv, clpcm_prv, sizeof(lpcm_prv));
//figure out size of subframe // figure out size of subframe and set up sample rate
//and set up sample rate
switch (uSampleRate) { switch (uSampleRate) {
case 48000: case 48000:
SubFrameLen = 40; SubFrameLen = 40;
@@ -172,8 +171,7 @@ static int prepareClipPlay(int uNoOfChannels, int uSampleRate,
case 16: case 16:
break; break;
default: default:
printf("inappropriate bits per sample (%d) - must be 16 or 24\n", printf("inappropriate bits per sample (%d) - must be 16 or 24\n", uBitsPerSample);
uBitsPerSample);
return 1; return 1;
} }
@@ -240,16 +238,12 @@ static int writeData(void *_call)
} }
//get first PES's worth //get first PES's worth
if (breakBufferFillSize > 0) { if (breakBufferFillSize > 0) {
memcpy(injectBuffer, breakBuffer, memcpy(injectBuffer, breakBuffer, sizeof(unsigned char) * breakBufferFillSize);
sizeof(unsigned char) * breakBufferFillSize); memcpy(&injectBuffer[breakBufferFillSize], &buffer[pos], sizeof(unsigned char) * (SubFrameLen - breakBufferFillSize));
memcpy(&injectBuffer[breakBufferFillSize], &buffer[pos],
sizeof(unsigned char) * (SubFrameLen -
breakBufferFillSize));
pos += (SubFrameLen - breakBufferFillSize); pos += (SubFrameLen - breakBufferFillSize);
breakBufferFillSize = 0; breakBufferFillSize = 0;
} else { } else {
memcpy(injectBuffer, &buffer[pos], memcpy(injectBuffer, &buffer[pos], sizeof(unsigned char) * SubFrameLen);
sizeof(unsigned char) * SubFrameLen);
pos += SubFrameLen; pos += SubFrameLen;
} }
@@ -291,9 +285,7 @@ static int writeData(void *_call)
//increment err... subframe count? //increment err... subframe count?
lpcm_prv[1] = ((lpcm_prv[1] + SubFramesPerPES) & 0x1F); lpcm_prv[1] = ((lpcm_prv[1] + SubFramesPerPES) & 0x1F);
iov[0].iov_len = iov[0].iov_len = InsertPesHeader(PesHeader, iov[1].iov_len + iov[2].iov_len, PCM_PES_START_CODE, call->Pts, 0);
InsertPesHeader(PesHeader, iov[1].iov_len + iov[2].iov_len,
PCM_PES_START_CODE, call->Pts, 0);
int len = writev(call->fd, iov, 3); int len = writev(call->fd, iov, 3);
if (len < 0) if (len < 0)
break; break;

View File

@@ -59,15 +59,18 @@ void cAudio::openDevice(void)
void cAudio::closeDevice(void) void cAudio::closeDevice(void)
{ {
if (fd >= 0) if (fd > -1) {
close(fd); close(fd);
fd = -1; fd = -1;
if (clipfd >= 0) }
if (clipfd > -1) {
close(clipfd); close(clipfd);
clipfd = -1; clipfd = -1;
if (mixer_fd >= 0) }
if (mixer_fd > -1) {
close(mixer_fd); close(mixer_fd);
mixer_fd = -1; mixer_fd = -1;
}
} }
int cAudio::do_mute(bool enable, bool remember) int cAudio::do_mute(bool enable, bool remember)
@@ -172,7 +175,7 @@ void cAudio::SetStreamType(AUDIO_FORMAT type)
case AUDIO_FMT_DD_PLUS: case AUDIO_FMT_DD_PLUS:
case AUDIO_FMT_DOLBY_DIGITAL: case AUDIO_FMT_DOLBY_DIGITAL:
bypass = AUDIO_STREAMTYPE_AC3; bypass = AUDIO_STREAMTYPE_AC3;
break; break;
case AUDIO_FMT_AAC: case AUDIO_FMT_AAC:
bypass = AUDIO_STREAMTYPE_AAC; bypass = AUDIO_STREAMTYPE_AAC;
break; break;
@@ -205,12 +208,11 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian)
const char *dsp_dev = getenv("DSP_DEVICE"); const char *dsp_dev = getenv("DSP_DEVICE");
const char *mix_dev = getenv("MIX_DEVICE"); const char *mix_dev = getenv("MIX_DEVICE");
lt_debug("%s ch %d srate %d bits %d le %d\n", __FUNCTION__, ch, srate, bits, little_endian); lt_debug("%s ch %d srate %d bits %d le %d\n", __FUNCTION__, ch, srate, bits, little_endian);
if (clipfd >= 0) { if (clipfd > -1) {
lt_info("%s: clipfd already opened (%d)\n", __FUNCTION__, clipfd); lt_info("%s: clipfd already opened (%d)\n", __FUNCTION__, clipfd);
return -1; return -1;
} }
mixer_num = -1; mixer_num = -1;
mixer_fd = -1;
/* a different DSP device can be given with DSP_DEVICE and MIX_DEVICE /* a different DSP device can be given with DSP_DEVICE and MIX_DEVICE
* if this device cannot be opened, we fall back to the internal OSS device * if this device cannot be opened, we fall back to the internal OSS device
* Example: * Example:
@@ -222,7 +224,7 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian)
if ((!dsp_dev) || (access(dsp_dev, W_OK))) { if ((!dsp_dev) || (access(dsp_dev, W_OK))) {
if (dsp_dev) if (dsp_dev)
lt_info("%s: DSP_DEVICE is set (%s) but cannot be opened," lt_info("%s: DSP_DEVICE is set (%s) but cannot be opened,"
" fall back to /dev/dsp1\n", __func__, dsp_dev); " fall back to /dev/dsp1\n", __func__, dsp_dev);
dsp_dev = "/dev/dsp1"; dsp_dev = "/dev/dsp1";
} }
lt_info("%s: dsp_dev %s mix_dev %s\n", __func__, dsp_dev, mix_dev); /* NULL mix_dev is ok */ lt_info("%s: dsp_dev %s mix_dev %s\n", __func__, dsp_dev, mix_dev); /* NULL mix_dev is ok */
@@ -267,7 +269,7 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian)
usable = devmask & stereo; usable = devmask & stereo;
if (usable == 0) { if (usable == 0) {
lt_info("%s: devmask: %08x stereo: %08x, no usable dev :-(\n", lt_info("%s: devmask: %08x stereo: %08x, no usable dev :-(\n",
__func__, devmask, stereo); __func__, devmask, stereo);
close(mixer_fd); close(mixer_fd);
mixer_fd = -1; mixer_fd = -1;
return 0; /* TODO: should we treat this as error? */ return 0; /* TODO: should we treat this as error? */
@@ -276,13 +278,13 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian)
if (__builtin_popcount (usable) != 1) { if (__builtin_popcount (usable) != 1) {
/* TODO: this code is not yet tested as I have only single-mixer devices... */ /* TODO: this code is not yet tested as I have only single-mixer devices... */
lt_info("%s: more than one mixer control: devmask %08x stereo %08x\n" lt_info("%s: more than one mixer control: devmask %08x stereo %08x\n"
"%s: querying MIX_NUMBER environment variable...\n", "%s: querying MIX_NUMBER environment variable...\n",
__func__, devmask, stereo, __func__); __func__, devmask, stereo, __func__);
const char *tmp = getenv("MIX_NUMBER"); const char *tmp = getenv("MIX_NUMBER");
if (tmp) if (tmp)
mixer_num = atoi(tmp); mixer_num = atoi(tmp);
lt_info("%s: mixer_num is %d -> device %08x\n", lt_info("%s: mixer_num is %d -> device %08x\n",
__func__, mixer_num, (mixer_num >= 0) ? (1 << mixer_num) : 0); __func__, mixer_num, (mixer_num >= 0) ? (1 << mixer_num) : 0);
/* no error checking, you'd better know what you are doing... */ /* no error checking, you'd better know what you are doing... */
} else { } else {
mixer_num = 0; mixer_num = 0;
@@ -300,7 +302,7 @@ int cAudio::WriteClip(unsigned char *buffer, int size)
{ {
int ret; int ret;
// lt_debug("cAudio::%s\n", __FUNCTION__); // lt_debug("cAudio::%s\n", __FUNCTION__);
if (clipfd <= 0) { if (clipfd < 0) {
lt_info("%s: clipfd not yet opened\n", __FUNCTION__); lt_info("%s: clipfd not yet opened\n", __FUNCTION__);
return -1; return -1;
} }
@@ -313,15 +315,16 @@ int cAudio::WriteClip(unsigned char *buffer, int size)
int cAudio::StopClip() int cAudio::StopClip()
{ {
lt_debug("%s\n", __FUNCTION__); lt_debug("%s\n", __FUNCTION__);
if (clipfd <= 0) { if (clipfd < 0) {
lt_info("%s: clipfd not yet opened\n", __FUNCTION__); lt_info("%s: clipfd not yet opened\n", __FUNCTION__);
return -1; return -1;
} }
close(clipfd); close(clipfd);
clipfd = -1; clipfd = -1;
if (mixer_fd >= 0) if (mixer_fd >= -1) {
close(mixer_fd); close(mixer_fd);
mixer_fd = -1; mixer_fd = -1;
}
setVolume(volume, volume); setVolume(volume, volume);
return 0; return 0;
}; };

View File

@@ -554,7 +554,7 @@ int cVideo::getBlank(void)
return 0; return 0;
while ((r = getline(&line, &n, f)) != -1) while ((r = getline(&line, &n, f)) != -1)
{ {
if (r <= strlen("mailbox")) /* should not happen... */ if (r <= (ssize_t) strlen("mailbox")) /* should not happen... */
continue; continue;
line[r - 1] = 0; /* remove \n */ line[r - 1] = 0; /* remove \n */
if (!strcmp(&line[r - 1 - strlen("mailbox")], "mailbox")) if (!strcmp(&line[r - 1 - strlen("mailbox")], "mailbox"))