summaryrefslogtreecommitdiff
path: root/src/ogg_pcm.c
blob: eb6a53e66f37d39c56b440e38e29c93591ccc7f6 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software ; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation ; either version 2.1 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
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program ; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/


#include "sfconfig.h"

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <math.h>

#if HAVE_UNISTD_H
#include <unistd.h>
#endif

#include "sndfile.h"
#include "sfendian.h"
#include "common.h"

#if (ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_LIBS)

#include <ogg/ogg.h>

#include "ogg.h"

typedef struct
{	int32_t serialno ;


	void * state ;
} OPCM_PRIVATE ;

static int	opcm_read_header (SF_PRIVATE * psf) ;
static int	opcm_close (SF_PRIVATE *psf) ;

int
ogg_pcm_open (SF_PRIVATE *psf)
{	OGG_PRIVATE* odata = psf->container_data ;
	OPCM_PRIVATE* opcm = calloc (1, sizeof (OPCM_PRIVATE)) ;
	int	error = 0 ;

	if (odata == NULL)
	{	psf_log_printf (psf, "%s : odata is NULL???\n", __func__) ;
		return SFE_INTERNAL ;
		} ;

	psf->codec_data = opcm ;
	if (opcm == NULL)
		return SFE_MALLOC_FAILED ;

	if (psf->file.mode == SFM_RDWR)
		return SFE_BAD_MODE_RW ;

	if (psf->file.mode == SFM_READ)
	{	/* Call this here so it only gets called once, so no memory is leaked. */
		ogg_sync_init (&odata->osync) ;

		if ((error = opcm_read_header (psf)))
			return error ;

#if 0
		psf->read_short		= opcm_read_s ;
		psf->read_int		= opcm_read_i ;
		psf->read_float		= opcm_read_f ;
		psf->read_double	= opcm_read_d ;
		psf->sf.frames		= opcm_length (psf) ;
#endif
		} ;

	psf->codec_close = opcm_close ;

	if (psf->file.mode == SFM_WRITE)
	{
#if 0
		/* Set the default opcm quality here. */
		vdata->quality = 0.4 ;

		psf->write_header	= opcm_write_header ;
		psf->write_short	= opcm_write_s ;
		psf->write_int		= opcm_write_i ;
		psf->write_float	= opcm_write_f ;
		psf->write_double	= opcm_write_d ;
#endif

		psf->sf.frames = SF_COUNT_MAX ; /* Unknown really */
		psf->str_flags = SF_STR_ALLOW_START ;
		} ;

	psf->bytewidth = 1 ;
	psf->blockwidth = psf->bytewidth * psf->sf.channels ;

#if 0
	psf->seek = opcm_seek ;
	psf->command = opcm_command ;
#endif

	/* FIXME, FIXME, FIXME : Hack these here for now and correct later. */
	psf->sf.format = SF_FORMAT_OGG | SF_FORMAT_SPEEX ;
	psf->sf.sections = 1 ;

	psf->datalength = 1 ;
	psf->dataoffset = 0 ;
	/* End FIXME. */

	return error ;
} /* ogg_pcm_open */

static int
opcm_read_header (SF_PRIVATE * UNUSED (psf))
{
	return 0 ;
} /* opcm_read_header */

static int
opcm_close (SF_PRIVATE * UNUSED (psf))
{


	return 0 ;
} /* opcm_close */



/*
encoded_speex_frames = (frames_per_packet * Packets)
                     = 1 * 272
                     = 272

audio_samples = encoded_speex_frames * frame_size
              = 272 * 640
              = 174080

duration = audio_samples / rate
         = 174080 / 44100
         = 3.947
*/

#else /* ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_LIBS */

int
ogg_pcm_open (SF_PRIVATE *psf)
{
	psf_log_printf (psf, "This version of libsndfile was compiled without Ogg/Speex support.\n") ;
	return SFE_UNIMPLEMENTED ;
} /* ogg_pcm_open */

#endif