/* * et_opus_read_file_info: * @file: file to read info from * @ETFileInfo: ET_File_Info to put information into * @error: a GError or %NULL * * Read header information of an Opus file. * * Returns: %TRUE if successful otherwise %FALSE */ gboolean et_opus_read_file_info (GFile *gfile, ET_File_Info *ETFileInfo, GError **error) { OggOpusFile *file; const OpusHead* head; GFileInfo *info; g_return_val_if_fail (gfile != NULL && ETFileInfo != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); file = et_opus_open_file (gfile, error); if (!file) { g_assert (error == NULL || *error != NULL); return FALSE; } /* FIXME: Improve error-checking. */ head = op_head (file, -1); /* TODO: Read the vendor string from the Vorbis comment? */ ETFileInfo->version = head->version; ETFileInfo->bitrate = op_bitrate (file, -1) / 1000; ETFileInfo->mode = head->channel_count; /* All Opus audio is encoded at 48 kHz, but the input sample rate can * differ, and then input_sample_rate will be set. */ if (head->input_sample_rate != 0) { ETFileInfo->samplerate = head->input_sample_rate; } else { ETFileInfo->samplerate = 48000; } ETFileInfo->duration = op_pcm_total (file, -1) / 48000; op_free (file); info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info) { ETFileInfo->size = g_file_info_get_size (info); g_object_unref (info); } else { ETFileInfo->size = 0; } g_assert (error == NULL || *error == NULL); return TRUE; }
/* * et_opus_tag_read_file_tag: * @filename: file from which to read tags * @FileTag: File_Tag to read tag into * @error: a GError or %NULL * * Read file tags and store into File_Tag. * * Returns: %TRUE if successful otherwise %FALSE */ gboolean et_opus_tag_read_file_tag (GFile *gfile, File_Tag *FileTag, GError **error) { OggOpusFile *file; const OpusTags *tags; GFileInfo *info; g_return_val_if_fail (gfile != NULL && FileTag != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); file = et_opus_open_file (gfile, error); if (!file) { g_assert (error == NULL || *error != NULL); return FALSE; } tags = op_tags (file, 0); info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, G_FILE_QUERY_INFO_NONE, NULL, error); if (!info) { op_free (file); g_assert (error == NULL || *error != NULL); return FALSE; } /* The cast is safe according to the opusfile documentation. */ et_add_file_tags_from_vorbis_comments ((vorbis_comment *)tags, FileTag, g_file_info_get_display_name (info)); g_object_unref (info); op_free (file); g_assert (error == NULL || *error == NULL); return TRUE; }