view libmpcodecs/ae_pcm.c @ 36316:139f2b064ef9

Don't subsequently calculate original_aspect from last movie_aspect. Instead, differentiate between the original aspect ratio stored in or determined from the video file and the forced, i.e. current, aspect ratio (e.g. forced by command line override). This enables multiple independent instances of vd.c again which has been broken by introducing a static variable in r36401. Without the subsequent calculation of original_aspect it now contains nothing but the pure video file aspect ratio which makes it possible to use movie_aspect -1 to set the original aspect ratio which explains the changes in command.c and gui/dialog/menu.c. The changes in vd_mpegpes due to the impact of original_aspect will fix a bug there at the same time where the condition in order to call mpcodecs_config_vo() should only trigger once when the encoded aspect changes. So far, the forced, i.e. current, aspect has been checked. The whole is related to enabling special argument -1 to switch_ratio started in r36391.
author ib
date Wed, 07 Aug 2013 20:41:34 +0000
parents c08363dc5320
children
line wrap: on
line source

/*
 * This file is part of MPlayer.
 *
 * MPlayer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * MPlayer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include "m_option.h"
#include "mp_msg.h"
#include "libmpdemux/aviheader.h"
#include "libaf/af_format.h"
#include "libaf/reorder_ch.h"
#include "libmpdemux/ms_hdr.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "ae_pcm.h"


static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a)
{
	mux_a->h.dwScale=1;
	mux_a->h.dwRate=encoder->params.sample_rate;
	mux_a->wf=malloc(sizeof(*mux_a->wf));
	mux_a->wf->wFormatTag=0x1; // PCM
	mux_a->wf->nChannels=encoder->params.channels;
	mux_a->h.dwSampleSize=2*mux_a->wf->nChannels;
	mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize;
	mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
	mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
	mux_a->wf->wBitsPerSample=16;
	mux_a->wf->cbSize=0; // FIXME for l3codeca.acm

	encoder->input_format = (mux_a->wf->wBitsPerSample==8) ? AF_FORMAT_U8 : AF_FORMAT_S16_LE;
	encoder->min_buffer_size = 16384;
	encoder->max_buffer_size = mux_a->wf->nAvgBytesPerSec;

	return 1;
}

static int encode_pcm(audio_encoder_t *encoder, uint8_t *dest, void *src, int nsamples, int max_size)
{
	max_size = FFMIN(nsamples, max_size);
	if (encoder->params.channels == 5 || encoder->params.channels == 6 ||
		    encoder->params.channels == 8) {
		max_size -= max_size % (encoder->params.channels * 2);
		reorder_channel_copy_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
		                         dest, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
		                         encoder->params.channels,
		                         max_size / 2, 2);
	}
	else
	memcpy(dest, src, max_size);
	return max_size;
}

static int set_decoded_len(audio_encoder_t *encoder, int len)
{
	return len;
}

static int close_pcm(audio_encoder_t *encoder)
{
	return 1;
}

static int get_frame_size(audio_encoder_t *encoder)
{
	return 0;
}

int mpae_init_pcm(audio_encoder_t *encoder)
{
	encoder->params.samples_per_frame = encoder->params.sample_rate;
	encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;

	encoder->decode_buffer_size = encoder->params.bitrate / 8;
	encoder->bind = bind_pcm;
	encoder->get_frame_size = get_frame_size;
	encoder->set_decoded_len = set_decoded_len;
	encoder->encode = encode_pcm;
	encoder->close = close_pcm;

	return 1;
}