2003-05-29 14:35:24 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
|
|
|
|
*
|
2006-04-01 16:50:49 +00:00
|
|
|
* ac3_padder.h: Pad AC3 frames for use with an SPDIF interface.
|
2003-05-29 14:35:24 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AC3_PADDER_INC
|
|
|
|
#define AC3_PADDER_INC
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* Size of an IEC958 padded AC3 frame. */
|
|
|
|
#define AC3P_IEC_FRAME_SIZE 6144
|
|
|
|
/* Size of the IEC958 header. */
|
|
|
|
#define AC3P_IEC_HEADER_SIZE 8
|
|
|
|
/* Size of the AC3 header. */
|
|
|
|
#define AC3P_AC3_HEADER_SIZE 7
|
|
|
|
|
|
|
|
|
|
|
|
/* An IEC958 padded AC3 frame. */
|
2004-03-15 16:32:54 +00:00
|
|
|
typedef struct {
|
2003-05-29 14:35:24 +00:00
|
|
|
/* IEC header. */
|
|
|
|
guchar header[AC3P_IEC_HEADER_SIZE];
|
|
|
|
|
|
|
|
/* Begin of AC3 header. */
|
|
|
|
guchar sync_byte1;
|
|
|
|
guchar sync_byte2;
|
|
|
|
|
|
|
|
guchar crc1[2];
|
|
|
|
guchar code;
|
|
|
|
guchar bsidmod;
|
|
|
|
guchar acmod;
|
|
|
|
/* End of AC3 header. */
|
2004-03-15 16:32:54 +00:00
|
|
|
|
|
|
|
unsigned char data[AC3P_IEC_FRAME_SIZE - AC3P_IEC_HEADER_SIZE
|
|
|
|
- AC3P_AC3_HEADER_SIZE];
|
2003-05-29 14:35:24 +00:00
|
|
|
} ac3p_iec958_burst_frame;
|
|
|
|
|
|
|
|
|
|
|
|
/* Possible states for the reading automaton: */
|
|
|
|
|
|
|
|
/* Searching for sync byte 1. */
|
|
|
|
#define AC3P_STATE_SYNC1 1
|
|
|
|
/* Searching for sync byte 2. */
|
|
|
|
#define AC3P_STATE_SYNC2 2
|
|
|
|
/* Reading AC3 header. */
|
|
|
|
#define AC3P_STATE_HEADER 3
|
|
|
|
/* Reading packet contents.*/
|
|
|
|
#define AC3P_STATE_CONTENT 4
|
|
|
|
|
|
|
|
|
|
|
|
/* Events generated by the parse function: */
|
|
|
|
|
|
|
|
/* The parser needs new data to be pushed. */
|
|
|
|
#define AC3P_EVENT_PUSH 1
|
|
|
|
/* There is a new padded frame ready to read from the padder structure. */
|
|
|
|
#define AC3P_EVENT_FRAME 2
|
|
|
|
|
|
|
|
|
|
|
|
/* The internal state for the padder. */
|
2004-03-15 16:32:54 +00:00
|
|
|
typedef struct {
|
|
|
|
guint state; /* State of the reading automaton. */
|
2003-05-29 14:35:24 +00:00
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
guchar *in_ptr; /* Input pointer, marking the current
|
|
|
|
postion in the input buffer. */
|
|
|
|
guint remaining; /* The number of bytes remaining in the current
|
|
|
|
reading buffer. */
|
2003-05-29 14:35:24 +00:00
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
guchar *out_ptr; /* Output pointer, marking the current
|
|
|
|
position in the output frame. */
|
2003-05-29 14:35:24 +00:00
|
|
|
guint bytes_to_copy;
|
2004-03-15 16:32:54 +00:00
|
|
|
/* Number of bytes that still must be copied
|
|
|
|
to the output frame *during this reading
|
|
|
|
stage*. */
|
2003-05-29 14:35:24 +00:00
|
|
|
|
|
|
|
guint ac3_frame_size;
|
2004-03-15 16:32:54 +00:00
|
|
|
/* The size in bytes of the pure AC3 portion
|
|
|
|
of the current frame. */
|
2003-05-29 14:35:24 +00:00
|
|
|
|
|
|
|
ac3p_iec958_burst_frame frame;
|
2004-03-15 16:32:54 +00:00
|
|
|
/* The current output frame. */
|
2003-05-29 14:35:24 +00:00
|
|
|
} ac3_padder;
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
extern void
|
|
|
|
ac3p_init(ac3_padder *padder);
|
2003-05-29 14:35:24 +00:00
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
extern void
|
|
|
|
ac3p_push_data(ac3_padder *padder, guchar *data, guint size);
|
2003-05-29 14:35:24 +00:00
|
|
|
|
2004-03-15 16:32:54 +00:00
|
|
|
extern int
|
|
|
|
ac3p_parse(ac3_padder *padder);
|
2003-05-29 14:35:24 +00:00
|
|
|
|
|
|
|
|
2006-04-01 16:50:49 +00:00
|
|
|
/*
|
2003-05-29 14:35:24 +00:00
|
|
|
* ac3p_frame
|
|
|
|
* @padder The padder structure.
|
|
|
|
*
|
|
|
|
* Returns a pointer to the padded frame contained in the padder.
|
|
|
|
*/
|
|
|
|
#define ac3p_frame(padder) ((guint *) &((padder)->frame))
|
|
|
|
|
2006-04-01 16:50:49 +00:00
|
|
|
/*
|
2003-05-29 14:35:24 +00:00
|
|
|
* ac3p_frame_size
|
|
|
|
* @padder The padder structure.
|
|
|
|
*
|
|
|
|
* Returns the length in bytes of the last read raw AC3 frame.
|
|
|
|
*/
|
|
|
|
#define ac3p_frame_size(padder) ((padder)->ac3_frame_size)
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|