Beispiel #1
0
static OpusTags *
tags_list(DB_playItem_t *it, OggOpusFile *opusfile, int link)
{
    const OpusTags *orig = op_tags (opusfile, link);

    OpusTags *tags = calloc (1, sizeof (OpusTags));
    if (!tags)
        return NULL;

    deadbeef->pl_lock ();
    for (DB_metaInfo_t *m = deadbeef->pl_get_metadata_head (it); m; m = m->next) {
        if (strchr (":!_", m->key[0])) {
            break;
        }
        char *key = strdupa (m->key);
        if (!strcasecmp(key, "R128_TRACK_GAIN")) {
            continue;
        }
        split_tag (tags, oggedit_map_tag (key, "meta2tag"), m->value, m->valuesize);
    }

    deadbeef->pl_unlock ();

    // preserve album art
    int i = 0;
    const char *tag;
    while ((tag = opus_tags_query(orig, ALBUM_ART_KEY, i++))) {
        split_tag (tags, ALBUM_ART_KEY, tag, (int)strlen (tag) + 1);
    }

    return tags;
}
Beispiel #2
0
// set flag operation and split tag name
int set_tag_filter(avt_filter_op operate, char *tag)
{
	AVER_ENTER;

	// assign setting
	g_filter_op = operate;

	// initial hash table
	reset_tag_hash_table();

	// split tag name
	split_tag(tag);

	AVER_LEAVE;
	return SUCCESS;
}
void *malloc(uint64_t size)
{
	int index;
	void *ptr;
	struct boundary_tag *tag = NULL;

	liballoc_lock();

		if ( l_initialized == 0 )
		{
			for ( index = 0; index < MAXEXP; index++ )
			{
				l_freePages[index] = NULL;
				l_completePages[index] = 0;
			}
			l_initialized = 1;
		}

		index = getexp( size ) + MODE;
		if ( index < MINEXP ) index = MINEXP;


		// Find one big enough.
			tag = l_freePages[ index ];				// Start at the front of the list.
			while ( tag != NULL )
			{
					// If there's enough space in this tag.
				if ( (tag->real_size - sizeof(struct boundary_tag))
								>= (size + sizeof(struct boundary_tag) ) )
				{
					break;
				}

				tag = tag->next;
			}


			// No page found. Make one.
			if ( tag == NULL )
			{
				if ( (tag = allocate_new_tag( size )) == NULL )
				{
					liballoc_unlock();
					return NULL;
				}

				index = getexp( tag->real_size - sizeof(struct boundary_tag) );
			}
			else
			{
				remove_tag( tag );

				if ( (tag->split_left == NULL) && (tag->split_right == NULL) )
					l_completePages[ index ] -= 1;
			}

		// We have a free page.  Remove it from the free pages list.

		tag->size = size;

		// Removed... see if we can re-use the excess space.

		unsigned int remainder = tag->real_size - size - sizeof( struct boundary_tag ) * 2; // Support a new tag + remainder

		if ( ((int)(remainder) > 0) /*&& ( (tag->real_size - remainder) >= (1<<MINEXP))*/ )
		{
			int childIndex = getexp( remainder );

			if ( childIndex >= 0 )
			{
				struct boundary_tag *new_tag = split_tag( tag );

				new_tag = new_tag;	// Get around the compiler warning about unused variables.
			}
		}



	ptr = (void*)((unsigned int)tag + sizeof( struct boundary_tag ) );

	liballoc_unlock();
	return ptr;
}
Beispiel #4
0
void *malloc(size_t size)
{
	int index;
	void *ptr;
	struct boundary_tag *tag = NULL;

	liballoc_lock();

		if ( l_initialized == 0 )
		{
			#ifdef DEBUG
			printf("%s\n","liballoc initializing.");
			#endif
			for ( index = 0; index < MAXEXP; index++ )
			{
				l_freePages[index] = NULL;
				l_completePages[index] = 0;
			}
			l_initialized = 1;
		}

		index = getexp( size ) + MODE;
		if ( index < MINEXP ) index = MINEXP;


		// Find one big enough.
			tag = l_freePages[ index ];				// Start at the front of the list.
			while ( tag != NULL )
			{
					// If there's enough space in this tag.
				if ( (tag->real_size - sizeof(struct boundary_tag))
								>= (size + sizeof(struct boundary_tag) ) )
				{
					#ifdef DEBUG
					printf("Tag search found %i >= %i\n",(tag->real_size - sizeof(struct boundary_tag)), (size + sizeof(struct boundary_tag) ) );
					#endif
					break;
				}

				tag = tag->next;
			}


			// No page found. Make one.
			if ( tag == NULL )
			{
				if ( (tag = allocate_new_tag( size )) == NULL )
				{
					liballoc_unlock();
					return NULL;
				}

				index = getexp( tag->real_size - sizeof(struct boundary_tag) );
			}
			else
			{
				remove_tag( tag );

				if ( (tag->split_left == NULL) && (tag->split_right == NULL) )
					l_completePages[ index ] -= 1;
			}

		// We have a free page.  Remove it from the free pages list.

		tag->size = size;

		// Removed... see if we can re-use the excess space.

		#ifdef DEBUG
		printf("Found tag with %i bytes available (requested %i bytes, leaving %i), which has exponent: %i (%i bytes)\n", tag->real_size - sizeof(struct boundary_tag), size, tag->real_size - size - sizeof(struct boundary_tag), index, 1<<index );
		#endif

		unsigned int remainder = tag->real_size - size - sizeof( struct boundary_tag ) * 2; // Support a new tag + remainder

		if ( ((int)(remainder) > 0) /*&& ( (tag->real_size - remainder) >= (1<<MINEXP))*/ )
		{
			int childIndex = getexp( remainder );

			if ( childIndex >= 0 )
			{
				#ifdef DEBUG
				printf("Seems to be splittable: %i >= 2^%i .. %i\n", remainder, childIndex, (1<<childIndex) );
				#endif

				struct boundary_tag *new_tag = split_tag( tag );

				new_tag = new_tag;	// Get around the compiler warning about unused variables.

				#ifdef DEBUG
				printf("Old tag has become %i bytes, new tag is now %i bytes (%i exp)\n", tag->real_size, new_tag->real_size, new_tag->index );
				#endif
			}
		}



	ptr = (void*)((unsigned int)tag + sizeof( struct boundary_tag ) );



	#ifdef DEBUG
	l_inuse += size;
	printf("malloc: %x,  %i, %i\n", ptr, (int)l_inuse / 1024, (int)l_allocated / 1024 );
	dump_array();
	#endif


	liballoc_unlock();
	return ptr;
}
Beispiel #5
0
static int
opusdec_write_metadata (DB_playItem_t *it) {
    char fname[PATH_MAX];
    deadbeef->pl_get_meta (it, ":URI", fname, sizeof (fname));

    DB_FILE *fp = deadbeef->fopen (fname);
    if (!fp) {
        return -1;
    }

    int is_streaming = fp->vfs->is_streaming();
    const OpusFileCallbacks opcb = {
        .read = opus_file_read,
        .seek = is_streaming ? NULL : opus_file_seek,
        .tell = is_streaming ? NULL : opus_file_tell,
        .close = opus_file_close
    };

    int res = 0;

    OggOpusFile *opusfile = op_test_callbacks(fp, &opcb, NULL, 0, &res);
    if (!opusfile) {
        deadbeef->fclose (fp);
        return -1;
    }

    int link = 0;
    if (deadbeef->pl_get_item_flags (it) & DDB_IS_SUBTRACK) {
        link = deadbeef->pl_find_meta_int (it, ":TRACKNUM", 0);
    }

    OpusTags *tags = tags_list(it, opusfile, link);
    if (!tags) {
        op_free (opusfile);
        deadbeef->fclose (fp);
        return -1;
    }

    deadbeef->pl_lock();

    // RG info
    const char *track_gain_str = deadbeef->pl_find_meta (it, ddb_internal_rg_keys[DDB_REPLAYGAIN_TRACKGAIN]);
    float track_gain = 0;
    if (track_gain_str) {
        track_gain = atof (track_gain_str);
    }

    const char *album_gain_str = deadbeef->pl_find_meta (it, ddb_internal_rg_keys[DDB_REPLAYGAIN_ALBUMGAIN]);
    float album_gain = 0;
    if (album_gain_str) {
        album_gain = atof (album_gain_str);
    }

    if (track_gain_str) {
        char s[100];
        snprintf (s, sizeof (s), "%d", 0);
        split_tag (tags, oggedit_map_tag (strdupa ("R128_TRACK_GAIN"), "meta2tag"), s, (int)strlen (s) + 1);
    }

    float value = deadbeef->pl_get_item_replaygain (it, DDB_REPLAYGAIN_ALBUMGAIN);
    if (value != 0) {
        char s[100];
        snprintf (s, sizeof (s), "%d", (int)(album_gain - track_gain) * 256);
        split_tag (tags, oggedit_map_tag (strdupa ("R128_ALBUM_GAIN"), "meta2tag"), s, (int)strlen (s) + 1);
    }

    int header_gain = (track_gain - 5.f) * 256;

    const char *stream_size_string = deadbeef->pl_find_meta(it, ":STREAM SIZE");
    const size_t stream_size = stream_size_string ? (off_t)atoll(stream_size_string) : 0;
    deadbeef->pl_unlock();
    const off_t file_size = oggedit_write_opus_metadata (deadbeef->fopen(fname), fname, 0, stream_size, header_gain, tags->comments, tags->user_comments);
    opus_tags_clear(tags);

    res = 0;
    if (file_size <= 0) {
        res = -1;
    }

    op_free (opusfile);
    deadbeef->fclose (fp);

    if (!res) {
        set_meta_ll(it, ":FILE_SIZE", (int64_t)file_size);
        res = opusdec_read_metadata(it);
    }
    return res;
}


// define plugin interface
static DB_decoder_t plugin = {
    DB_PLUGIN_SET_API_VERSION
    .plugin.version_major = 1,
    .plugin.version_minor = 0,
    .plugin.type = DB_PLUGIN_DECODER,
    .plugin.flags = DDB_PLUGIN_FLAG_LOGGING,
    .plugin.name = "Opus player",
    .plugin.id = "opus",
    .plugin.descr = "Opus player based on libogg, libopus and libopusfile.",
    .plugin.copyright = 
        "deadbeef-opus\n"
        "Copyright (C) 2009-2017 Alexey Yakovenko and other contributors\n"
        "\n"
        "This software is provided 'as-is', without any express or implied\n"
        "warranty.  In no event will the authors be held liable for any damages\n"
        "arising from the use of this software.\n"
        "\n"
        "Permission is granted to anyone to use this software for any purpose,\n"
        "including commercial applications, and to alter it and redistribute it\n"
        "freely, subject to the following restrictions:\n"
        "\n"
        "1. The origin of this software must not be misrepresented; you must not\n"
        " claim that you wrote the original software. If you use this software\n"
        " in a product, an acknowledgment in the product documentation would be\n"
        " appreciated but is not required.\n"
        "\n"
        "2. Altered source versions must be plainly marked as such, and must not be\n"
        " misrepresented as being the original software.\n"
        "\n"
        "3. This notice may not be removed or altered from any source distribution.\n"
        "\n\n\n"
        "libogg, opus, opusfile\n"
        "Copyright (c) 1994-2013 Xiph.Org Foundation and contributors\n"
        "\n\n\n"
        "liboggedit\n"
        "Copyright (C) 2014 Ian Nartowicz <*****@*****.**>\n",
    .open = opusdec_open,
    .open2 = opusdec_open2,
    .init = opusdec_init,
    .free = opusdec_free,
    .read = opusdec_read,
    .seek = opusdec_seek,
    .seek_sample = opusdec_seek_sample,
    .insert = opusdec_insert,
    .read_metadata = opusdec_read_metadata,
    .write_metadata = opusdec_write_metadata,
    .exts = exts,
};

DB_plugin_t *
opus_load (DB_functions_t *api) {
    deadbeef = api;
    return DB_PLUGIN (&plugin);
}