/*****************************************************************************
- * rawdv.c : raw dv input module for vlc
+ * rawdv.c : raw DV input module for vlc
*****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: rawdv.c,v 1.6 2003/04/27 14:56:47 gbazin Exp $
+ * Copyright (C) 2001-2007 the VideoLAN team
+ * $Id$
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
+ * Paul Corke <paul dot corke at datatote dot co dot uk>
*
* This program 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.
- *
+ *
* This program 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
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <stdlib.h> /* malloc(), free() */
-#include <string.h> /* strdup() */
-#include <errno.h>
-#include <vlc/vlc.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_demux.h>
+
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+#define HURRYUP_TEXT N_( "Hurry up" )
+#define HURRYUP_LONGTEXT N_( "The demuxer will advance timestamps if the " \
+ "input can't keep up with the rate." )
+
+static int Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
-#include <sys/types.h>
+vlc_module_begin ()
+ set_shortname( "DV" )
+ set_description( N_("DV (Digital Video) demuxer") )
+ set_capability( "demux", 3 )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_DEMUX )
+ add_bool( "rawdv-hurry-up", false, HURRYUP_TEXT, HURRYUP_LONGTEXT, false )
+ set_callbacks( Open, Close )
+ add_shortcut( "rawdv" )
+vlc_module_end ()
-#include <codecs.h> /* BITMAPINFOHEADER, WAVEFORMATEX */
/*****************************************************************************
A little bit of background information (copied over from libdv glossary).
- DIF block: A block of 80 bytes. This is the basic data framing unit of the
DVC tape format, analogous to sectors of hard disc.
-
+
- Video Section: Each DIF sequence contains a video section, consisting of
135 DIF blocks, which are further subdivided into Video Segments.
{
int frame_size;
- es_descriptor_t *p_video_es;
- es_descriptor_t *p_audio_es;
+ es_out_id_t *p_es_video;
+ es_format_t fmt_video;
- /* codec specific stuff */
- BITMAPINFOHEADER *p_bih;
- WAVEFORMATEX *p_wf;
+ es_out_id_t *p_es_audio;
+ es_format_t fmt_audio;
+ int i_dsf;
double f_rate;
int i_bitrate;
/* program clock reference (in units of 90kHz) */
mtime_t i_pcr;
+ bool b_hurry_up;
};
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-static int Activate ( vlc_object_t * );
-static void Deactivate( vlc_object_t * );
-static int Demux ( input_thread_t * );
+static int Demux( demux_t * );
+static int Control( demux_t *, int i_query, va_list args );
-static uint32_t GetDWBE( uint8_t *p_buff )
-{
- return (uint32_t)p_buff[3] | ( ((uint32_t)p_buff[2]) << 8 ) |
- ( ((uint32_t)p_buff[1]) << 16 ) | ( ((uint32_t)p_buff[0]) << 24 );
-}
+static block_t *dv_extract_audio( demux_t *p_demux,
+ block_t* p_frame_block );
/*****************************************************************************
- * Module descriptor
+ * Open: initializes raw DV demux structures
*****************************************************************************/
-vlc_module_begin();
- set_description( _("raw dv demuxer") );
- set_capability( "demux", 2 );
- set_callbacks( Activate, NULL );
- add_shortcut( "rawdv" );
-vlc_module_end();
-
-/*****************************************************************************
- * Activate: initializes raw dv demux structures
- *****************************************************************************/
-static int Activate( vlc_object_t * p_this )
+static int Open( vlc_object_t * p_this )
{
- input_thread_t *p_input = (input_thread_t *)p_this;
- byte_t *p_peek, *p_peek_backup;
- uint32_t i_dword;
- demux_sys_t *p_rawdv;
- dv_header_t dv_header;
- dv_id_t dv_id;
- char *psz_ext;
-
- /* It isn't easy to recognize a raw dv stream. The chances that we'll
- * mistake a stream from another type for a raw dv stream are too high, so
+ demux_t *p_demux = (demux_t*)p_this;
+ demux_sys_t *p_sys;
+
+ const uint8_t *p_peek, *p_peek_backup;
+
+ uint32_t i_dword;
+ dv_header_t dv_header;
+ dv_id_t dv_id;
+
+ /* It isn't easy to recognize a raw DV stream. The chances that we'll
+ * mistake a stream from another type for a raw DV stream are too high, so
* we'll rely on the file extension to trigger this demux. Alternatively,
* it is possible to force this demux. */
- /* Check for dv file extension */
- psz_ext = strrchr ( p_input->psz_name, '.' );
- if( ( !psz_ext || strcasecmp( psz_ext, ".dv") )&&
- ( !p_input->psz_demux || strcmp(p_input->psz_demux, "rawdv") ) )
- {
- return -1;
- }
-
- p_input->pf_demux = Demux;
+ /* Check for DV file extension */
+ if( !demux_IsPathExtension( p_demux, ".dv" ) && !p_demux->b_force )
+ return VLC_EGENERIC;
- /* Have a peep at the show. */
- if( input_Peek(p_input, &p_peek, DV_PAL_FRAME_SIZE) < DV_NTSC_FRAME_SIZE )
+ if( stream_Peek( p_demux->s, &p_peek, DV_PAL_FRAME_SIZE ) <
+ DV_NTSC_FRAME_SIZE )
{
/* Stream too short ... */
- msg_Err( p_input, "cannot peek()" );
- return -1;
+ msg_Err( p_demux, "cannot peek()" );
+ return VLC_EGENERIC;
}
p_peek_backup = p_peek;
if( dv_id.sct != 0 )
{
- msg_Warn( p_input, "not a raw dv stream header" );
- return -1;
+ msg_Warn( p_demux, "not a raw DV stream header" );
+ return VLC_EGENERIC;
}
/* fill in the dv_header_t structure */
i_dword <<= 1;
if( i_dword >> (32 - 1) ) /* incorrect bit */
{
- msg_Warn( p_input, "incorrect bit" );
- return -1;
+ msg_Warn( p_demux, "incorrect bit" );
+ return VLC_EGENERIC;
}
i_dword = GetDWBE( p_peek ); p_peek += 4;
p_peek += 72; /* skip rest of DIF block */
+ /* Set p_input field */
+ p_demux->pf_demux = Demux;
+ p_demux->pf_control = Control;
+ p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
+ if( !p_sys )
+ return VLC_ENOMEM;
- /* Setup the structures for our demuxer */
- if( !( p_rawdv = malloc( sizeof( demux_sys_t ) ) ) )
- {
- msg_Err( p_input, "out of memory" );
- return -1;
- }
- memset( p_rawdv, 0, sizeof( demux_sys_t ) );
- p_rawdv->p_bih = NULL;
- p_rawdv->p_wf = NULL;
- p_input->p_demux_data = p_rawdv;
+ p_sys->b_hurry_up = var_CreateGetBool( p_demux, "rawdv-hurry-up" );
+ msg_Dbg( p_demux, "Realtime DV Source: %s", (p_sys->b_hurry_up)?"Yes":"No" );
- p_rawdv->p_bih = (BITMAPINFOHEADER *) malloc( sizeof(BITMAPINFOHEADER) );
- if( !p_rawdv->p_bih )
- {
- msg_Err( p_input, "out of memory" );
- goto error;
- }
- p_rawdv->p_bih->biSize = sizeof(BITMAPINFOHEADER);
- p_rawdv->p_bih->biCompression = VLC_FOURCC( 'd','v','s','d' );
- p_rawdv->p_bih->biSize = 40;
- p_rawdv->p_bih->biWidth = 720;
- p_rawdv->p_bih->biHeight = dv_header.dsf ? 576 : 480;
- p_rawdv->p_bih->biPlanes = 1;
- p_rawdv->p_bih->biBitCount = 24;
- p_rawdv->p_bih->biSizeImage =
- p_rawdv->p_bih->biWidth * p_rawdv->p_bih->biHeight
- * (p_rawdv->p_bih->biBitCount >> 3);
-
- /* Properties of our video */
- if( dv_header.dsf )
- {
- p_rawdv->frame_size = 12 * 150 * 80;
- p_rawdv->f_rate = 25;
- }
- else
- {
- p_rawdv->frame_size = 10 * 150 * 80;
- p_rawdv->f_rate = 29.97;
- }
-
- /* Audio stuff */
-#if 0
- p_peek = p_peek_backup + 80*6+80*16*3 + 3; /* beginning of AAUX pack */
-
- if( *p_peek != 0x50 || *p_peek != 0x51 )
- {
- msg_Err( p_input, "AAUX should begin with 0x50" );
- }
-#endif
+ p_sys->i_dsf = dv_header.dsf;
+ p_sys->frame_size = dv_header.dsf ? 12 * 150 * 80 : 10 * 150 * 80;
+ p_sys->f_rate = dv_header.dsf ? 25 : 29.97;
- p_rawdv->p_wf = (WAVEFORMATEX *)malloc( sizeof(WAVEFORMATEX) );
- if( !p_rawdv->p_wf )
- {
- msg_Err( p_input, "out of memory" );
- goto error;
- }
+ p_sys->i_pcr = 0;
+ p_sys->p_es_video = NULL;
+ p_sys->p_es_audio = NULL;
- p_rawdv->p_wf->wFormatTag = 0;
- p_rawdv->p_wf->nChannels = 2;
- p_rawdv->p_wf->nSamplesPerSec = 44100; /* FIXME */
- p_rawdv->p_wf->nAvgBytesPerSec = p_rawdv->f_rate * p_rawdv->frame_size;
- p_rawdv->p_wf->nBlockAlign = p_rawdv->frame_size;
- p_rawdv->p_wf->wBitsPerSample = 16;
- p_rawdv->p_wf->cbSize = 0;
+ p_sys->i_bitrate = 0;
+ es_format_Init( &p_sys->fmt_video, VIDEO_ES, VLC_CODEC_DV );
+ p_sys->fmt_video.video.i_width = 720;
+ p_sys->fmt_video.video.i_height= dv_header.dsf ? 576 : 480;;
+ /* FIXME FIXME */
+#if 0
/* necessary because input_SplitBuffer() will only get
* INPUT_DEFAULT_BUFSIZE bytes at a time. */
- p_input->i_bufsize = p_rawdv->frame_size;
+ p_input->i_bufsize = p_sys->frame_size;
+#endif
- /* Create one program */
- vlc_mutex_lock( &p_input->stream.stream_lock );
- if( input_InitStream( p_input, 0 ) == -1)
- {
- vlc_mutex_unlock( &p_input->stream.stream_lock );
- msg_Err( p_input, "cannot init stream" );
- goto error;
- }
- if( input_AddProgram( p_input, 0, 0) == NULL )
+ p_sys->p_es_video = es_out_Add( p_demux->out, &p_sys->fmt_video );
+
+ /* Audio stuff */
+ p_peek = p_peek_backup + 80*6+80*16*3 + 3; /* beginning of AAUX pack */
+ if( *p_peek == 0x50 )
{
- vlc_mutex_unlock( &p_input->stream.stream_lock );
- msg_Err( p_input, "cannot add program" );
- goto error;
+ /* 12 bits non-linear will be converted to 16 bits linear */
+ es_format_Init( &p_sys->fmt_audio, AUDIO_ES, VLC_CODEC_S16L );
+
+ p_sys->fmt_audio.audio.i_bitspersample = 16;
+ p_sys->fmt_audio.audio.i_channels = 2;
+ switch( (p_peek[4] >> 3) & 0x07 )
+ {
+ case 0:
+ p_sys->fmt_audio.audio.i_rate = 48000;
+ break;
+ case 1:
+ p_sys->fmt_audio.audio.i_rate = 44100;
+ break;
+ case 2:
+ default:
+ p_sys->fmt_audio.audio.i_rate = 32000;
+ break;
+ }
+
+ p_sys->p_es_audio = es_out_Add( p_demux->out, &p_sys->fmt_audio );
}
- p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
- p_input->stream.i_mux_rate = p_rawdv->frame_size * p_rawdv->f_rate;
- vlc_mutex_unlock( &p_input->stream.stream_lock );
-
- /* Add video stream */
- vlc_mutex_lock( &p_input->stream.stream_lock );
- p_rawdv->p_video_es = input_AddES( p_input,
- p_input->stream.p_selected_program,
- 1, 0 );
- p_rawdv->p_video_es->i_stream_id = 0;
- p_rawdv->p_video_es->i_fourcc = VLC_FOURCC( 'd','v','s','d' );
- p_rawdv->p_video_es->i_cat = VIDEO_ES;
- p_rawdv->p_video_es->p_bitmapinfoheader = (void *)p_rawdv->p_bih;
- input_SelectES( p_input, p_rawdv->p_video_es );
- vlc_mutex_unlock( &p_input->stream.stream_lock );
-
- /* Add audio stream */
- vlc_mutex_lock( &p_input->stream.stream_lock );
- p_rawdv->p_audio_es = input_AddES( p_input,
- p_input->stream.p_selected_program,
- 2, 0 );
- p_rawdv->p_audio_es->i_stream_id = 1;
- p_rawdv->p_audio_es->i_fourcc = VLC_FOURCC( 'd','v','a','u' );
- p_rawdv->p_audio_es->i_cat = AUDIO_ES;
- p_rawdv->p_audio_es->p_waveformatex = (void *)p_rawdv->p_wf;
- input_SelectES( p_input, p_rawdv->p_audio_es );
- vlc_mutex_unlock( &p_input->stream.stream_lock );
-
- /* Init pcr */
- p_rawdv->i_pcr = 0;
-
- return 0;
-
- error:
- if( p_rawdv->p_bih ) free( p_rawdv->p_bih );
- if( p_rawdv->p_wf ) free( p_rawdv->p_wf );
- Deactivate( (vlc_object_t *)p_input );
- return -1;
+
+ return VLC_SUCCESS;
}
/*****************************************************************************
- * Deactivate: frees unused data
+ * Close: frees unused data
*****************************************************************************/
-static void Deactivate( vlc_object_t *p_this )
+static void Close( vlc_object_t *p_this )
{
- input_thread_t *p_input = (input_thread_t *)p_this;
- demux_sys_t *p_rawdv = (demux_sys_t *)p_input->p_demux_data;
+ demux_t *p_demux = (demux_t*)p_this;
+ demux_sys_t *p_sys = p_demux->p_sys;
- free( p_rawdv );
+ var_Destroy( p_demux, "rawdv-hurry-up");
+ free( p_sys );
}
/*****************************************************************************
*****************************************************************************
* Returns -1 in case of error, 0 in case of EOF, 1 otherwise
*****************************************************************************/
-static int Demux( input_thread_t * p_input )
+static int Demux( demux_t *p_demux )
{
- demux_sys_t *p_rawdv = (demux_sys_t *)p_input->p_demux_data;
- pes_packet_t *p_pes;
- pes_packet_t *p_audio_pes;
- data_packet_t *p_data;
- ssize_t i_read;
+ demux_sys_t *p_sys = p_demux->p_sys;
+ block_t *p_block;
+ bool b_audio = false;
- if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
+ if( p_sys->b_hurry_up )
{
- off_t i_pos;
+ /* 3 frames */
+ p_sys->i_pcr = mdate() + (p_sys->i_dsf ? 120000 : 90000);
+ }
- msg_Warn( p_input, "synchro reinit" );
+ /* Call the pace control */
+ es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pcr );
+ p_block = stream_Block( p_demux->s, p_sys->frame_size );
+ if( p_block == NULL )
+ {
+ /* EOF */
+ return 0;
+ }
- /* If the user tried to seek in the stream, we need to make sure
- * the new position is at a DIF block boundary. */
- vlc_mutex_lock( &p_input->stream.stream_lock );
- i_pos= p_input->stream.p_selected_area->i_tell;
- vlc_mutex_unlock( &p_input->stream.stream_lock );
+ if( p_sys->p_es_audio )
+ {
+ es_out_Control( p_demux->out, ES_OUT_GET_ES_STATE,
+ p_sys->p_es_audio, &b_audio );
+ }
- if( (i_pos % p_rawdv->frame_size) &&
- p_input->stream.b_seekable &&
- p_input->stream.i_method == INPUT_METHOD_FILE )
+ p_block->i_dts =
+ p_block->i_pts = VLC_TS_0 + p_sys->i_pcr;
+
+ if( b_audio )
+ {
+ block_t *p_audio_block = dv_extract_audio( p_demux, p_block );
+ if( p_audio_block )
{
- p_input->pf_seek( p_input, (i_pos / p_rawdv->frame_size)
- * p_rawdv->frame_size );
- input_AccessReinit( p_input );
+ p_audio_block->i_pts =
+ p_audio_block->i_dts = VLC_TS_0 + p_sys->i_pcr;
+ es_out_Send( p_demux->out, p_sys->p_es_audio, p_audio_block );
}
}
- /* Call the pace control */
- input_ClockManageRef( p_input, p_input->stream.p_selected_program,
- p_rawdv->i_pcr );
+ es_out_Send( p_demux->out, p_sys->p_es_video, p_block );
- i_read = input_SplitBuffer( p_input, &p_data, p_rawdv->frame_size );
- if( i_read <= 0 )
+ if( !p_sys->b_hurry_up )
{
- return i_read;
+ p_sys->i_pcr += ( INT64_C(1000000) / p_sys->f_rate );
}
- /* Build video PES packet */
- if( p_rawdv->p_video_es->p_decoder_fifo )
- {
- p_pes = input_NewPES( p_input->p_method_data );
- if( p_pes == NULL )
- {
- msg_Err( p_input, "out of memory" );
- input_DeletePacket( p_input->p_method_data, p_data );
- return -1;
- }
+ return 1;
+}
- p_pes->i_rate = p_input->stream.control.i_rate;
- p_pes->p_first = p_pes->p_last = p_data;
- p_pes->i_pes_size = i_read;
- p_pes->i_nb_data = 1;
- p_pes->i_pts =
- input_ClockGetTS( p_input, p_input->stream.p_selected_program,
- p_rawdv->i_pcr );
+/*****************************************************************************
+ * Control:
+ *****************************************************************************/
+static int Control( demux_t *p_demux, int i_query, va_list args )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+
+ /* XXX: DEMUX_SET_TIME is precise here */
+ return demux_vaControlHelper( p_demux->s,
+ 0, -1,
+ p_sys->frame_size * p_sys->f_rate * 8,
+ p_sys->frame_size, i_query, args );
+}
+
+static const uint16_t dv_audio_shuffle525[10][9] = {
+ { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
+ { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
+ { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
+ { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
+ { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
+
+ { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
+ { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
+ { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
+ { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
+ { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
+};
+
+static const uint16_t dv_audio_shuffle625[12][9] = {
+ { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
+ { 6, 42, 78, 32, 68, 104, 22, 58, 94},
+ { 12, 48, 84, 2, 38, 74, 28, 64, 100},
+ { 18, 54, 90, 8, 44, 80, 34, 70, 106},
+ { 24, 60, 96, 14, 50, 86, 4, 40, 76},
+ { 30, 66, 102, 20, 56, 92, 10, 46, 82},
+
+ { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
+ { 7, 43, 79, 33, 69, 105, 23, 59, 95},
+ { 13, 49, 85, 3, 39, 75, 29, 65, 101},
+ { 19, 55, 91, 9, 45, 81, 35, 71, 107},
+ { 25, 61, 97, 15, 51, 87, 5, 41, 77},
+ { 31, 67, 103, 21, 57, 93, 11, 47, 83},
+};
+
+static inline uint16_t dv_audio_12to16( uint16_t sample )
+{
+ uint16_t shift, result;
+
+ sample = (sample < 0x800) ? sample : sample | 0xf000;
+ shift = (sample & 0xf00) >> 8;
+
+ if (shift < 0x2 || shift > 0xd) {
+ result = sample;
+ } else if (shift < 0x8) {
+ shift--;
+ result = (sample - (256 * shift)) << shift;
+ } else {
+ shift = 0xe - shift;
+ result = ((sample + ((256 * shift) + 1)) << shift) - 1;
+ }
+
+ return result;
+}
+
+static block_t *dv_extract_audio( demux_t *p_demux,
+ block_t* p_frame_block )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ block_t *p_block;
+ uint8_t *p_frame, *p_buf;
+ int i_audio_quant, i_samples, i_size, i_half_ch;
+ const uint16_t (*audio_shuffle)[9];
+ int i, j, d, of;
+ uint16_t lc;
+
+ /* Beginning of AAUX pack */
+ p_buf = p_frame_block->p_buffer + 80*6+80*16*3 + 3;
+ if( *p_buf != 0x50 ) return NULL;
+
+ i_audio_quant = p_buf[4] & 0x07; /* 0 - 16bit, 1 - 12bit */
+ if( i_audio_quant > 1 )
+ {
+ msg_Dbg( p_demux, "unsupported quantization for DV audio");
+ return NULL;
}
- /* Do the same for audio */
- if( p_rawdv->p_audio_es->p_decoder_fifo )
+ i_samples = p_buf[1] & 0x3f; /* samples in this frame - min samples */
+ switch( (p_buf[4] >> 3) & 0x07 )
{
- p_audio_pes = input_NewPES( p_input->p_method_data );
- if( p_pes == NULL )
- {
- msg_Err( p_input, "out of memory" );
- input_DeletePacket( p_input->p_method_data, p_data );
- return -1;
- }
- p_audio_pes->i_rate = p_input->stream.control.i_rate;
-
- if( p_rawdv->p_video_es->p_decoder_fifo )
- p_audio_pes->p_first = p_audio_pes->p_last =
- input_ShareBuffer( p_input->p_method_data, p_data->p_buffer );
- else
- p_audio_pes->p_first = p_audio_pes->p_last = p_data;
-
- p_audio_pes->p_first->p_next = p_data->p_next;
- p_audio_pes->p_first->p_payload_start = p_data->p_payload_start;
- p_audio_pes->p_first->p_payload_end = p_data->p_payload_end;
- p_audio_pes->i_pes_size = i_read;
- p_audio_pes->i_nb_data = 1;
- p_audio_pes->i_pts =
- input_ClockGetTS( p_input, p_input->stream.p_selected_program,
- p_rawdv->i_pcr );
+ case 0:
+ i_size = p_sys->i_dsf ? 1896 : 1580;
+ break;
+ case 1:
+ i_size = p_sys->i_dsf ? 1742 : 1452;
+ break;
+ case 2:
+ default:
+ i_size = p_sys->i_dsf ? 1264 : 1053;
+ break;
}
+ i_size = (i_size + i_samples) * 4; /* 2ch, 2bytes */
- /* Decode PES packets if stream is selected */
- if( p_rawdv->p_video_es->p_decoder_fifo )
- input_DecodePES( p_rawdv->p_video_es->p_decoder_fifo, p_pes );
- if( p_rawdv->p_audio_es->p_decoder_fifo )
- input_DecodePES( p_rawdv->p_audio_es->p_decoder_fifo, p_audio_pes );
+ p_block = block_New( p_demux, i_size );
- p_rawdv->i_pcr += ( 90000 / p_rawdv->f_rate );
+ /* for each DIF segment */
+ p_frame = p_frame_block->p_buffer;
+ audio_shuffle = p_sys->i_dsf ? dv_audio_shuffle625 : dv_audio_shuffle525;
+ i_half_ch = (p_sys->i_dsf ? 12 : 10)/2;
+ for( i = 0; i < (p_sys->i_dsf ? 12 : 10); i++ )
+ {
+ p_frame += 6 * 80; /* skip DIF segment header */
- if( !p_rawdv->p_video_es->p_decoder_fifo &&
- !p_rawdv->p_audio_es->p_decoder_fifo )
- input_DeletePacket( p_input->p_method_data, p_data );
+ if( i_audio_quant == 1 && i == i_half_ch ) break;
- return 1;
+ for( j = 0; j < 9; j++ )
+ {
+ for( d = 8; d < 80; d += 2 )
+ {
+ if( i_audio_quant == 0 )
+ {
+ /* 16bit quantization */
+ of = audio_shuffle[i][j] + (d - 8) / 2 *
+ (p_sys->i_dsf ? 108 : 90);
+
+ if( of * 2 >= i_size ) continue;
+
+ /* big endian */
+ p_block->p_buffer[of*2] = p_frame[d+1];
+ p_block->p_buffer[of*2+1] = p_frame[d];
+
+ if( p_block->p_buffer[of*2+1] == 0x80 &&
+ p_block->p_buffer[of*2] == 0x00 )
+ p_block->p_buffer[of*2+1] = 0;
+ }
+ else
+ {
+ /* 12bit quantization */
+ lc = ((uint16_t)p_frame[d] << 4) |
+ ((uint16_t)p_frame[d+2] >> 4);
+ lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
+
+ of = audio_shuffle[i][j] + (d - 8) / 3 *
+ (p_sys->i_dsf ? 108 : 90);
+ if( of*2 >= i_size ) continue;
+
+ /* big endian */
+ p_block->p_buffer[of*2] = lc & 0xff;
+ p_block->p_buffer[of*2+1] = lc >> 8;
+ ++d;
+ }
+ }
+
+ p_frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
+ }
+ }
+
+ return p_block;
}