/* Fill info structure with data from ogg comments */ static void vorbis_tags (const char *file_name, struct file_tags *info, const int tags_sel) { OggVorbis_File vf; FILE *file; int err_code; if (!(file = fopen (file_name, "r"))) { logit ("Can't open an OGG file: %s", strerror(errno)); return; } /* ov_test() is faster than ov_open(), but we can't read file time * with it. */ if (tags_sel & TAGS_TIME) { if ((err_code = ov_open(file, &vf, NULL, 0)) < 0) { char *vorbis_err = vorbis_strerror (err_code); logit ("Can't open %s: %s", file_name, vorbis_err); free (vorbis_err); fclose (file); return; } } else { if ((err_code = ov_test(file, &vf, NULL, 0)) < 0) { char *vorbis_err = vorbis_strerror (err_code); logit ("Can't open %s: %s", file_name, vorbis_err); free (vorbis_err); fclose (file); return; } } if (tags_sel & TAGS_COMMENTS) get_comment_tags (&vf, info); if (tags_sel & TAGS_TIME) { int64_t vorbis_time; vorbis_time = ov_time_total (&vf, -1); if (vorbis_time >= 0) info->time = vorbis_time / time_scaler; } ov_clear (&vf); }
static bool vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf, struct decoder *decoder, struct input_stream *input_stream) { vis->decoder = decoder; vis->input_stream = input_stream; vis->seekable = input_stream->seekable && (input_stream->uri == NULL || !uri_has_scheme(input_stream->uri)); int ret = ov_open_callbacks(vis, vf, NULL, 0, vorbis_is_callbacks); if (ret < 0) { if (decoder == NULL || decoder_get_command(decoder) == DECODE_COMMAND_NONE) g_warning("Failed to open Ogg Vorbis stream: %s", vorbis_strerror(ret)); return false; } return true; }
int VorbisDecoder_init(decoders_VorbisDecoder *self, PyObject *args, PyObject *kwds) { char* filename; ogg_status ogg_result; vorbis_status vorbis_result; self->ogg_stream = NULL; self->ogg_file = NULL; self->packet = br_substream_new(BS_LITTLE_ENDIAN); if (!PyArg_ParseTuple(args, "s", &filename)) goto error; self->ogg_file = fopen(filename, "rb"); if (self->ogg_file == NULL) { PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename); goto error; } else { self->ogg_stream = oggreader_open(self->ogg_file); } /*read identification packet*/ if ((ogg_result = oggreader_next_packet(self->ogg_stream, self->packet)) == OGG_OK) { if ((vorbis_result = vorbis_read_identification_packet(self->packet, &(self->identification))) != VORBIS_OK) { PyErr_SetString(vorbis_exception(vorbis_result), vorbis_strerror(vorbis_result)); goto error; } } else { PyErr_SetString(ogg_exception(ogg_result), ogg_strerror(ogg_result)); goto error; } /*skip comments packet, but ensure it's positioned properly*/ if ((ogg_result = oggreader_next_packet(self->ogg_stream, self->packet)) == OGG_OK) { if (vorbis_read_common_header(self->packet) != 3) { PyErr_SetString(PyExc_ValueError, "comment not second Ogg packet"); goto error; } } else { PyErr_SetString(ogg_exception(ogg_result), ogg_strerror(ogg_result)); goto error; } /*read setup header*/ if ((ogg_result = oggreader_next_packet(self->ogg_stream, self->packet)) == OGG_OK) { if ((vorbis_result = vorbis_read_setup_packet(self->packet)) != VORBIS_OK) { PyErr_SetString(vorbis_exception(vorbis_result), vorbis_strerror(vorbis_result)); goto error; } } else { PyErr_SetString(ogg_exception(ogg_result), ogg_strerror(ogg_result)); goto error; } return 0; error: return -1; }