summaryrefslogtreecommitdiff
path: root/sys/dxr3/ac3_padder.h
blob: f2ca2faafaf3d87945ee4ce2a8d5a57d2abe35e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* GStreamer
 * Copyright (C) 2003 Martin Soto <martinsoto@users.sourceforge.net>
 *
 * ac3_padder.h: Pad AC3 frames for use with an SPDIF interface. 
 *
 * 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. */
typedef struct
{
  /* 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. */

  unsigned char data[AC3P_IEC_FRAME_SIZE - AC3P_IEC_HEADER_SIZE
      - AC3P_AC3_HEADER_SIZE];
} 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. */
typedef struct
{
  guint state;			/* State of the reading automaton. */

  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. */

  guchar *out_ptr;		/* Output pointer, marking the current
				   position in the output frame. */
  guint bytes_to_copy;
  /* Number of bytes that still must be copied
     to the output frame *during this reading
     stage*. */

  guint ac3_frame_size;
  /* The size in bytes of the pure AC3 portion
     of the current frame. */

  ac3p_iec958_burst_frame frame;
  /* The current output frame. */
} ac3_padder;



extern void ac3p_init (ac3_padder * padder);

extern void ac3p_push_data (ac3_padder * padder, guchar * data, guint size);

extern int ac3p_parse (ac3_padder * padder);


/**
 * ac3p_frame
 * @padder The padder structure.
 *
 * Returns a pointer to the padded frame contained in the padder.
 */
#define ac3p_frame(padder) ((guint *) &((padder)->frame))

/**
 * 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