Esempio n. 1
0
bool get_asf_metadata(int fd, struct mp3entry* id3)
{
    int res;
    asf_object_t obj;
    asf_waveformatex_t wfx;

    wfx.audiostream = -1;

    res = asf_parse_header(fd, id3, &wfx);

    if (res < 0) {
        DEBUGF("ASF: parsing error - %d\n",res);
        return false;
    }

    if (wfx.audiostream == -1) {
        DEBUGF("ASF: No WMA streams found\n");
        return false;
    }

    asf_read_object_header(&obj, fd);

    if (!asf_guid_match(&obj.guid, &asf_guid_data)) {
        DEBUGF("ASF: No data object found\n");
        return false;
    }

    /* Store the current file position - no need to parse the header
       again in the codec.  The +26 skips the rest of the data object
       header.
     */
    id3->first_frame_offset = lseek(fd, 0, SEEK_CUR) + 26;
    id3->filesize = filesize(fd);
    /* We copy the wfx struct to the MP3 TOC field in the id3 struct so
       the codec doesn't need to parse the header object again */
    memcpy(id3->toc, &wfx, sizeof(wfx));

    return true;
}
Esempio n. 2
0
int
asf_init(asf_file_t *file)
{
	int tmp;

	if (!file)
		return ASF_ERROR_INTERNAL;

	tmp = asf_parse_header(file);
	if (tmp < 0) {
		debug_printf("error parsing header: %d", tmp);
		return tmp;
	}
	file->position += tmp;
	file->data_position = file->position;

	tmp = asf_parse_data(file);
	if (tmp < 0) {
		debug_printf("error parsing data object: %d", tmp);
		return tmp;
	}
	file->position += tmp;

	if (file->flags & ASF_FLAG_SEEKABLE && file->iostream.seek) {
		int64_t seek_position;

		file->index_position = file->data_position +
		                       file->data->size;

		seek_position = file->iostream.seek(file->iostream.opaque,
		                                    file->index_position);

		/* if first seek fails, we can try to recover and just ignore seeking */
		if (seek_position >= 0) {
			while (seek_position == file->index_position &&
			       file->index_position < file->file_size && !file->index) {
				tmp = asf_parse_index(file);
				if (tmp < 0) {
					debug_printf("Error finding index object! %d", tmp);
					break;
				}

				/* The object read was something else than index */
				if (!file->index)
					file->index_position += tmp;

				seek_position = file->iostream.seek(file->iostream.opaque,
								  file->index_position);
			}

			if (!file->index) {
				debug_printf("Couldn't find an index object");
				file->index_position = 0;
			}

			seek_position = file->iostream.seek(file->iostream.opaque,
							  file->data->packets_position);
			if (seek_position != file->data->packets_position) {
				/* Couldn't seek back to packets position, this is fatal! */
				return ASF_ERROR_SEEK;
			}
		}
	}

	for (tmp = 0; tmp < ASF_MAX_STREAMS; tmp++) {
		if (file->streams[tmp].type != ASF_STREAM_TYPE_NONE) {
			debug_printf("stream %d of type %d found!", tmp, file->streams[tmp].type);
		}
	}

	return 0;
}