comparison stream/stream_cdda.c @ 25410:38ef388859a9

Add cdda stream control for chapter commmands. Now we support seek cdda/cddb tracks by seek_chapter command.
author ulion
date Mon, 17 Dec 2007 15:20:28 +0000
parents 163348bb1e4a
children 68015115f63a
comparison
equal deleted inserted replaced
25409:54f9e0e764fd 25410:38ef388859a9
94 94
95 static int seek(stream_t* s,off_t pos); 95 static int seek(stream_t* s,off_t pos);
96 static int fill_buffer(stream_t* s, char* buffer, int max_len); 96 static int fill_buffer(stream_t* s, char* buffer, int max_len);
97 static void close_cdda(stream_t* s); 97 static void close_cdda(stream_t* s);
98 98
99 static int get_track_by_sector(cdda_priv *p, unsigned int sector) {
100 int i;
101 for (i = p->cd->tracks; i >= 0 ; --i)
102 if (p->cd->disc_toc[i].dwStartSector <= sector)
103 break;
104 return i;
105 }
106
107 static int control(stream_t *stream, int cmd, void *arg) {
108 cdda_priv* p = stream->priv;
109 switch(cmd) {
110 case STREAM_CTRL_GET_NUM_CHAPTERS:
111 {
112 int start_track = get_track_by_sector(p, p->start_sector);
113 int end_track = get_track_by_sector(p, p->end_sector);
114 *(unsigned int *)arg = end_track + 1 - start_track;
115 return STREAM_OK;
116 }
117 case STREAM_CTRL_SEEK_TO_CHAPTER:
118 {
119 int r;
120 unsigned int track = *(unsigned int *)arg;
121 int start_track = get_track_by_sector(p, p->start_sector);
122 int seek_sector;
123 track += start_track;
124 if (track >= p->cd->tracks) {
125 stream->eof = 1;
126 return STREAM_ERROR;
127 }
128 seek_sector = track <= 0 ? p->start_sector
129 : p->cd->disc_toc[track].dwStartSector;
130 r = seek(stream, seek_sector * CD_FRAMESIZE_RAW);
131 if (r)
132 return STREAM_OK;
133 break;
134 }
135 case STREAM_CTRL_GET_CURRENT_CHAPTER:
136 {
137 int start_track = get_track_by_sector(p, p->start_sector);
138 int cur_track = get_track_by_sector(p, p->sector);
139 *(unsigned int *)arg = cur_track - start_track;
140 return STREAM_OK;
141 }
142 }
143 return STREAM_UNSUPPORTED;
144 }
145
99 static int open_cdda(stream_t *st,int m, void* opts, int* file_format) { 146 static int open_cdda(stream_t *st,int m, void* opts, int* file_format) {
100 struct cdda_params* p = (struct cdda_params*)opts; 147 struct cdda_params* p = (struct cdda_params*)opts;
101 int mode = p->paranoia_mode; 148 int mode = p->paranoia_mode;
102 int offset = p->toc_offset; 149 int offset = p->toc_offset;
103 #ifndef HAVE_LIBCDIO 150 #ifndef HAVE_LIBCDIO
265 st->type = STREAMTYPE_CDDA; 312 st->type = STREAMTYPE_CDDA;
266 st->sector_size = CD_FRAMESIZE_RAW; 313 st->sector_size = CD_FRAMESIZE_RAW;
267 314
268 st->fill_buffer = fill_buffer; 315 st->fill_buffer = fill_buffer;
269 st->seek = seek; 316 st->seek = seek;
317 st->control = control;
270 st->close = close_cdda; 318 st->close = close_cdda;
271 319
272 *file_format = DEMUXER_TYPE_RAWAUDIO; 320 *file_format = DEMUXER_TYPE_RAWAUDIO;
273 321
274 m_struct_free(&stream_opts,opts); 322 m_struct_free(&stream_opts,opts);