"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/input-avcodec.c" between
potamus-16.tar.gz and potamus-17.tar.gz

About: Potamus is a lightweight GTK-based audio player with a simple interface and an emphasis on high audio quality.

input-avcodec.c  (potamus-16):input-avcodec.c  (potamus-17)
/* /*
* Potamus: an audio player * Potamus: an audio player
* Copyright (C) 2004, 2005, 2006, 2007, 2009, 2012 Adam Sampson <ats@offog.org> * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2012, 2016 Adam Sampson <ats@offo g.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the * published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version. * License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details. * General Public License for more details.
skipping to change at line 44 skipping to change at line 44
int64_t pos; int64_t pos;
int seekable; int seekable;
} iavc; } iavc;
static int input_avcodec_open(input *p, const char *fn) { static int input_avcodec_open(input *p, const char *fn) {
iavc *a = malloc(sizeof *a); iavc *a = malloc(sizeof *a);
if (a == NULL) if (a == NULL)
g_error("out of memory"); g_error("out of memory");
p->data = a; p->data = a;
a->frame = avcodec_alloc_frame(); a->frame = av_frame_alloc();
for (int pass = 0; pass < 2; pass++) { for (int pass = 0; pass < 2; pass++) {
a->format = NULL; a->format = NULL;
a->stream = -1; a->stream = -1;
a->codec_ctx = NULL; a->codec_ctx = NULL;
a->pos = 0; a->pos = 0;
a->seekable = 0; a->seekable = 0;
if (avformat_open_input(&a->format, fn, NULL, NULL) < 0) if (avformat_open_input(&a->format, fn, NULL, NULL) < 0)
return -1; return -1;
skipping to change at line 81 skipping to change at line 81
if (pass == 1) { if (pass == 1) {
// We've tried once already -- must not be seekable. // We've tried once already -- must not be seekable.
break; break;
} else if (av_seek_frame(a->format, a->stream, 0, 0) == 0) { } else if (av_seek_frame(a->format, a->stream, 0, 0) == 0) {
// Seeking worked. // Seeking worked.
a->seekable = 1; a->seekable = 1;
break; break;
} else { } else {
// Seeking didn't work -- reopen the file. // Seeking didn't work -- reopen the file.
avcodec_close(a->codec_ctx); avcodec_free_context(&a->codec_ctx);
av_free(a->codec_ctx);
avformat_close_input(&a->format); avformat_close_input(&a->format);
} }
} }
return 0; return 0;
} }
static int input_avcodec_get_audio(input *p, buffer *buf) { static int input_avcodec_get_audio(input *p, buffer *buf) {
iavc *a = (iavc *) p->data; iavc *a = (iavc *) p->data;
skipping to change at line 117 skipping to change at line 116
av_free_packet(&packet); av_free_packet(&packet);
} }
// We're going to shift the data pointer in this structure, so // We're going to shift the data pointer in this structure, so
// save a copy to allow us to free it safely later. // save a copy to allow us to free it safely later.
orig = packet; orig = packet;
// Decode the packet. // Decode the packet.
while (packet.size > 0) { while (packet.size > 0) {
avcodec_get_frame_defaults(a->frame); av_frame_unref(a->frame);
int got_frame = 0; int got_frame = 0;
int in_used = avcodec_decode_audio4(a->codec_ctx, int in_used = avcodec_decode_audio4(a->codec_ctx,
a->frame, a->frame,
&got_frame, &got_frame,
&packet); &packet);
if (in_used < 0) { if (in_used < 0) {
// Decoding error -- skip this frame. // Decoding error -- skip this frame.
break; break;
} }
skipping to change at line 161 skipping to change at line 160
} }
a->pos = packet.pts; a->pos = packet.pts;
av_free_packet(&orig); av_free_packet(&orig);
} while (out_size == 0); } while (out_size == 0);
p->fmt.bits = av_get_bytes_per_sample(a->codec_ctx->sample_fmt) * 8; p->fmt.bits = av_get_bytes_per_sample(a->codec_ctx->sample_fmt) * 8;
p->fmt.rate = a->codec_ctx->sample_rate; p->fmt.rate = a->codec_ctx->sample_rate;
p->fmt.channels = a->codec_ctx->channels; p->fmt.channels = a->codec_ctx->channels;
// FIXME not necessarily -- or planar!
p->fmt.byte_format = END_NATIVE; p->fmt.byte_format = END_NATIVE;
// FIXME handle planar formats
// FIXME use libswresample?
// avformat does provide the total bitrate, but we only want the stream // avformat does provide the total bitrate, but we only want the stream
// we're decoding. // we're decoding.
double num_samples = (1.0L * out_size) double num_samples = (1.0L * out_size)
/ ((p->fmt.bits / 8) * p->fmt.channels); / ((p->fmt.bits / 8) * p->fmt.channels);
p->bitrate = 8.0L * in_total p->bitrate = 8.0L * in_total
/ ((num_samples / p->fmt.rate) * 1000.0L); / ((num_samples / p->fmt.rate) * 1000.0L);
return out_size; return out_size;
} }
skipping to change at line 227 skipping to change at line 227
flags |= AVSEEK_FLAG_ANY; flags |= AVSEEK_FLAG_ANY;
if (av_seek_frame(a->format, a->stream, timestamp, flags) < 0) if (av_seek_frame(a->format, a->stream, timestamp, flags) < 0)
return -1; return -1;
return 0; return 0;
} }
static int input_avcodec_close(input *p) { static int input_avcodec_close(input *p) {
iavc *a = (iavc *) p->data; iavc *a = (iavc *) p->data;
if (a->codec_ctx != NULL) { if (a->codec_ctx != NULL)
avcodec_close(a->codec_ctx); avcodec_free_context(&a->codec_ctx);
av_free(a->codec_ctx);
}
if (a->format != NULL) if (a->format != NULL)
avformat_close_input(&a->format); avformat_close_input(&a->format);
av_free(a->frame); av_frame_free(&a->frame);
free(a); free(a);
free(p); free(p);
return 0; return 0;
} }
input *input_new_avcodec(void) { input *input_new_avcodec(void) {
static gboolean initialised = FALSE; static gboolean initialised = FALSE;
if (!initialised) { if (!initialised) {
 End of changes. 8 change blocks. 
11 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)