1 /*
2 ** Copyright (C) 2008-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** This program is free software ; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation ; either version 2.1 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY ; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program ; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19
20 #include "sfconfig.h"
21
22 #include <stdio.h>
23 #include <fcntl.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <time.h>
27 #include <math.h>
28
29 #if HAVE_UNISTD_H
30 #include <unistd.h>
31 #else
32 #include "sf_unistd.h"
33 #endif
34
35 #include "sndfile.h"
36 #include "sfendian.h"
37 #include "common.h"
38
39 #if (ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_XIPH_LIBS)
40
41 #include <ogg/ogg.h>
42
43 #include "ogg.h"
44
45 typedef struct
46 { int32_t serialno ;
47
48
49 void * state ;
50 } OPCM_PRIVATE ;
51
52 static int opcm_read_header (SF_PRIVATE * psf) ;
53 static int opcm_close (SF_PRIVATE *psf) ;
54
55 int
ogg_pcm_open(SF_PRIVATE * psf)56 ogg_pcm_open (SF_PRIVATE *psf)
57 { OGG_PRIVATE* odata = psf->container_data ;
58 OPCM_PRIVATE* opcm = calloc (1, sizeof (OPCM_PRIVATE)) ;
59 int error = 0 ;
60
61 if (odata == NULL)
62 { psf_log_printf (psf, "%s : odata is NULL???\n", __func__) ;
63 free (opcm) ;
64 return SFE_INTERNAL ;
65 } ;
66
67 psf->codec_data = opcm ;
68 if (opcm == NULL)
69 return SFE_MALLOC_FAILED ;
70
71 if (psf->file.mode == SFM_RDWR)
72 return SFE_BAD_MODE_RW ;
73
74 if (psf->file.mode == SFM_READ)
75 { /* Call this here so it only gets called once, so no memory is leaked. */
76 ogg_sync_init (&odata->osync) ;
77
78 if ((error = opcm_read_header (psf)))
79 return error ;
80
81 #if 0
82 psf->read_short = opcm_read_s ;
83 psf->read_int = opcm_read_i ;
84 psf->read_float = opcm_read_f ;
85 psf->read_double = opcm_read_d ;
86 psf->sf.frames = opcm_length (psf) ;
87 #endif
88 } ;
89
90 psf->codec_close = opcm_close ;
91
92 if (psf->file.mode == SFM_WRITE)
93 {
94 #if 0
95 /* Set the default opcm quality here. */
96 vdata->quality = 0.4 ;
97
98 psf->write_header = opcm_write_header ;
99 psf->write_short = opcm_write_s ;
100 psf->write_int = opcm_write_i ;
101 psf->write_float = opcm_write_f ;
102 psf->write_double = opcm_write_d ;
103 #endif
104
105 psf->sf.frames = SF_COUNT_MAX ; /* Unknown really */
106 psf->strings.flags = SF_STR_ALLOW_START ;
107 } ;
108
109 psf->bytewidth = 1 ;
110 psf->blockwidth = psf->bytewidth * psf->sf.channels ;
111
112 #if 0
113 psf->seek = opcm_seek ;
114 psf->command = opcm_command ;
115 #endif
116
117 /* FIXME, FIXME, FIXME : Hack these here for now and correct later. */
118 psf->sf.format = SF_FORMAT_OGG | SF_FORMAT_SPEEX ;
119 psf->sf.sections = 1 ;
120
121 psf->datalength = 1 ;
122 psf->dataoffset = 0 ;
123 /* End FIXME. */
124
125 return error ;
126 } /* ogg_pcm_open */
127
128 static int
opcm_read_header(SF_PRIVATE * UNUSED (psf))129 opcm_read_header (SF_PRIVATE * UNUSED (psf))
130 {
131 return 0 ;
132 } /* opcm_read_header */
133
134 static int
opcm_close(SF_PRIVATE * UNUSED (psf))135 opcm_close (SF_PRIVATE * UNUSED (psf))
136 {
137
138
139 return 0 ;
140 } /* opcm_close */
141
142
143
144 /*
145 encoded_speex_frames = (frames_per_packet * Packets)
146 = 1 * 272
147 = 272
148
149 audio_samples = encoded_speex_frames * frame_size
150 = 272 * 640
151 = 174080
152
153 duration = audio_samples / rate
154 = 174080 / 44100
155 = 3.947
156 */
157
158 #else /* ENABLE_EXPERIMENTAL_CODE && HAVE_EXTERNAL_XIPH_LIBS */
159
160 int
ogg_pcm_open(SF_PRIVATE * psf)161 ogg_pcm_open (SF_PRIVATE *psf)
162 {
163 psf_log_printf (psf, "This version of libsndfile was compiled without Ogg/Speex support.\n") ;
164 return SFE_UNIMPLEMENTED ;
165 } /* ogg_pcm_open */
166
167 #endif
168