static void fileSanitySeek(file::ptr f, pfc::array_t<uint8_t> const & content, size_t offset, abort_callback & aborter) {
	const size_t readAmount = 64 * 1024;
	pfc::array_staticsize_t<uint8_t> buf; buf.set_size_discard(readAmount);
	f->seek(offset, aborter);
	t_filesize positionGot = f->get_position(aborter);
	if (positionGot != offset) {
		FB2K_console_formatter() << "File sanity: at " << offset << " reported position became " << positionGot;
		throw std::runtime_error("Seek test failure");
	}
	size_t did = f->read(buf.get_ptr(), readAmount, aborter);
	size_t expected = pfc::min_t<size_t>(readAmount, content.get_size() - offset);
	if (expected != did) {
		FB2K_console_formatter() << "File sanity: at " << offset << " bytes, expected read size of " << expected << ", got " << did;
		if (did > expected) FB2K_console_formatter() << "Read past EOF";
		else  FB2K_console_formatter() << "Premature EOF";
		throw std::runtime_error("Seek test failure");
	}
	if (memcmp(buf.get_ptr(), content.get_ptr() + offset, did) != 0) {
		FB2K_console_formatter() << "File sanity: data mismatch at " << offset << " - " << (offset + did) << " bytes";
		throw std::runtime_error("Seek test failure");
	}
	positionGot = f->get_position(aborter);
	if (positionGot != offset + did) {
		FB2K_console_formatter() << "File sanity: at " << offset << "+" << did << "=" << (offset + did) << " reported position became " << positionGot;
		throw std::runtime_error("Seek test failure");
	}
}
Beispiel #2
0
    bool decode_run(audio_chunk & p_chunk, abort_callback & p_abort)
    {
        size_t data_size = m_decoder->decode_frame(&sample_buffer);

        if (config.format == 6)
        {
            p_chunk.set_data_floatingpoint_ex(
                sample_buffer.get_ptr(),
                data_size,
                m_decoder->sample_rate,
                config.speakers,
                get_bps_for_format(config.format),
                get_flags_for_format(config.format),
                get_channel_config_for_speakers(config.speakers));
        }
        else
        {
            p_chunk.set_data_fixedpoint_ex(
                sample_buffer.get_ptr(),
                data_size,
                m_decoder->sample_rate,
                config.speakers,
                get_bps_for_format(config.format),
                get_flags_for_format(config.format),
                get_channel_config_for_speakers(config.speakers));
        }

        return (data_size > 0);
    }
Beispiel #3
0
	virtual HRESULT STDMETHODCALLTYPE Seek( 
		LARGE_INTEGER dlibMove,
		DWORD dwOrigin,
		ULARGE_INTEGER *plibNewPosition)
	{
		if (dwOrigin == STREAM_SEEK_CUR)
		{
			if (dlibMove.QuadPart + (LONGLONG)m_position < 0
				|| dlibMove.QuadPart + (LONGLONG)m_position > MAXDWORD)
				return STG_E_INVALIDFUNCTION;
			m_position += (t_size)dlibMove.QuadPart; //Cast should be OK by if condition
		}
		else if (dwOrigin == STREAM_SEEK_END)
		{
			if (dlibMove.QuadPart + (LONGLONG)m_data.get_size() < 0)
				return STG_E_INVALIDFUNCTION;
			m_position = m_data.get_size() - (t_size)dlibMove.QuadPart; //Cast should be OK by if condition
		}
		else if (dwOrigin == STREAM_SEEK_SET)
		{
			if ((ULONGLONG)dlibMove.QuadPart > MAXDWORD)
				return STG_E_INVALIDFUNCTION;
			m_position = (t_size)dlibMove.QuadPart; //Cast should be OK by if condition
		}
		else
			return STG_E_INVALIDFUNCTION;
		if (plibNewPosition)
			plibNewPosition->QuadPart = m_position;
		return S_OK;
	}
Beispiel #4
0
HRESULT IDataObjectUtils::STGMEDIUMToDataBlock(const STGMEDIUM & med, pfc::array_t<t_uint8> & out) {
	switch(med.tymed) {
		case TYMED_HGLOBAL:
			{
				CGlobalLockScope lock(med.hGlobal);
				out.set_data_fromptr( (const t_uint8*) lock.GetPtr(), lock.GetSize() );
			}
			return S_OK;
		case TYMED_ISTREAM:
			{
				HRESULT state;
				IStream * stream = med.pstm;
				LARGE_INTEGER offset = {};
				STATSTG stats = {};
				if (FAILED( state = stream->Stat(&stats,STATFLAG_NONAME ) ) ) return state;
				t_size toRead = pfc::downcast_guarded<t_size>(stats.cbSize.QuadPart);
				out.set_size(toRead);
				if (FAILED( state = stream->Seek(offset,STREAM_SEEK_SET,NULL) ) ) return state;
				ULONG cbRead = 0;
				if (FAILED( state = stream->Read(out.get_ptr(), pfc::downcast_guarded<ULONG>(toRead), &cbRead) ) ) return state;
				if (cbRead != toRead) return E_UNEXPECTED;
			}
			return S_OK;
		default:
			return DV_E_TYMED;
	}
}
Beispiel #5
0
	bool decode_run( audio_chunk & p_chunk, abort_callback & p_abort )
	{
		if (!loop && is_playing == 0) return false;
		int nbSample = 512;
		sample_buffer.grow_size( nbSample );
		is_playing = ModPlug_Read(m_player, sample_buffer.get_ptr(), nbSample*2);
		p_chunk.set_data_fixedpoint( sample_buffer.get_ptr(), nbSample * 2, 44100, 2, 32, audio_chunk::channel_config_stereo );
		return true;
	}
Beispiel #6
0
	bool decode_run( audio_chunk & p_chunk, abort_callback & p_abort )
	{
		if (!loop && m_info.musicTimeInMs == ymMusicGetPos(m_player)) return false;
		int nbSample = 500 / sizeof(ymsample);
		sample_buffer.grow_size( nbSample );
		ymMusicCompute(m_player,sample_buffer.get_ptr(), nbSample);
		p_chunk.set_data_fixedpoint( sample_buffer.get_ptr(), nbSample * 2, 44100, 1, 16, audio_chunk::channel_config_mono );
		return true;
	}
Beispiel #7
0
	void get_info( file_info & p_info, abort_callback & p_abort )
	{
		ModPlugFile* m_info = ModPlug_Load(file_buffer.get_ptr(), file_buffer.get_size());
		p_info.info_set( "encoding", "synthesized" );
		int type_module = ModPlug_GetModuleType(m_info);
		p_info.info_set( "codec", "Module file" );
		p_info.info_set_int( "channels", 2 );
		p_info.meta_set( "title", pfc::stringcvt::string_utf8_from_ansi(  ModPlug_GetName(m_info)  ));
		int len = ModPlug_GetLength(m_info);
		len /= 1000;
		p_info.set_length( len );
		if(m_info)ModPlug_Unload(m_info);
	}
Beispiel #8
0
	virtual /* [local] */ HRESULT STDMETHODCALLTYPE Read( 
		/* [length_is][size_is][out] */ void *pv,
		/* [in] */ ULONG cb,
		/* [out] */ ULONG *pcbRead)
	{
		if (m_position > m_data.get_size())
			return STG_E_INVALIDFUNCTION;
		t_size read = min (cb, m_data.get_size() - m_position);
		memcpy(pv, &m_data.get_ptr()[m_position], read);
		m_position += read;
		if (pcbRead)
			*pcbRead = read;
		return S_OK;
	}
	void cleanup()
	{
		filter.set_size( 0 );
		srate = 0;
		nch = 0;
		channel_config = 0;
	}
Beispiel #10
0
	void get_info( file_info & p_info, abort_callback & p_abort )
	{
		YMMUSIC *  m_info = ymMusicCreate();
		ymMusicLoadMemory(m_info,file_buffer.get_ptr(), file_buffer.get_size());
		ymMusicInfo_t info;
		ymMusicGetInfo(m_info,&info);

		p_info.info_set( "encoding", "synthesized" );
		p_info.info_set( "codec", "YM" );
		p_info.info_set_int( "channels", 1 );
		p_info.meta_set( "title", pfc::stringcvt::string_utf8_from_ansi( info.pSongName) );
		p_info.meta_set( "artist", pfc::stringcvt::string_utf8_from_ansi( info.pSongAuthor) );
		p_info.meta_set( "comment", pfc::stringcvt::string_utf8_from_ansi( info.pSongComment) );
		p_info.set_length( info.musicTimeInSec );

		ymMusicDestroy(m_info);
	}
Beispiel #11
0
	virtual /* [local] */ HRESULT STDMETHODCALLTYPE Write( 
		/* [size_is][in] */ const void *pv,
		/* [in] */ ULONG cb,
		/* [out] */ ULONG *pcbWritten)
	{
		t_size old_size = m_data.get_size(), new_size = m_position + cb;
		if (new_size > old_size)
		{
			m_data.grow_size(new_size);
			memset(&m_data.get_ptr()[old_size], 0,new_size-new_size);
		}
		memcpy(&m_data.get_ptr()[m_position], pv, cb);
		m_position += cb;
		if (pcbWritten)
			*pcbWritten = cb;
		return S_OK;
	}
Beispiel #12
0
	virtual HRESULT STDMETHODCALLTYPE SetSize( 
		ULARGE_INTEGER libNewSize)
	{
		if (libNewSize.QuadPart > MAXDWORD)
			return STG_E_INVALIDFUNCTION;
		m_data.set_size((t_size)libNewSize.QuadPart);
		return S_OK;
	}
Beispiel #13
0
	void open( service_ptr_t<file> m_file, const char * p_path, t_input_open_reason p_reason, abort_callback & p_abort )
	{
		if ( p_reason == input_open_info_write ) throw exception_io_data();
		input_open_file_helper( m_file, p_path, p_reason, p_abort );
		m_stats = m_file->get_stats( p_abort );
		t_uint8            * ptr;
		unsigned             size;
		t_filesize size64 = m_file->get_size_ex( p_abort );
		if ( size64 > ( 1 << 24 ) )
			throw exception_io_data();
		size = (unsigned) size64;
		file_buffer.set_size( size );
		ptr = file_buffer.get_ptr();
		m_file->read_object( ptr, size, p_abort );
		m_player = ModPlug_Load(ptr, size);
		if ( !m_player ) throw exception_io_data();
	}
void stream_to_mem_block(stream_reader * p_source, pfc::array_t<t_uint8> & p_out,abort_callback & p_abort, unsigned p_sizehint, bool b_reset)
{
	if (b_reset)
		p_out.set_size(0);

	enum {min_buffer = 256};
	const unsigned buffer_size = max (min_buffer, p_sizehint);
	pfc::array_t<t_uint8> buffer;
	buffer.set_size(buffer_size);

	for(;;)
	{
		unsigned delta_done = 0;
		delta_done = p_source->read(buffer.get_ptr(),buffer_size,p_abort);
		p_out.append_fromptr(buffer.get_ptr(),delta_done);
		if (delta_done < buffer_size) break;
	}
}
Beispiel #15
0
	virtual HRESULT STDMETHODCALLTYPE CopyTo( 
		/* [unique][in] */ IStream *pstm,
		/* [in] */ ULARGE_INTEGER cb,
		/* [out] */ ULARGE_INTEGER *pcbRead,
		/* [out] */ ULARGE_INTEGER *pcbWritten)
	{
		if (cb.QuadPart > m_data.get_size() - m_position)
			return STG_E_INVALIDFUNCTION;
		t_size read = min ((t_size)cb.QuadPart, m_data.get_size() - m_position);
		ULONG pwritten = NULL;
		pstm->Write(&m_data.get_ptr()[m_position], read, &pwritten);
		m_position += read;
		if (pcbRead)
			pcbRead->QuadPart = read;
		if (pcbWritten)
			pcbWritten->QuadPart = pwritten;
		return S_OK;
	}
	void init()
	{
		filter.set_size( nch );
		for ( unsigned h = 0; h < nch; h++ )
		{
			//these do not matter, only samplerate does
			filter[ h ].setFrequency(400);
			filter[ h ].setQuality(0);
			filter[ h ].setGain(0);
			filter[ h ].init(srate,RIAA_CD);
		}
	}
Beispiel #17
0
bool g_get_resource_data (INT_PTR id, pfc::array_t<t_uint8> & p_out)
{
	bool ret = false;
	HRSRC rsrc = FindResource(core_api::get_my_instance(), MAKEINTRESOURCE(IDB_NOCOVER), L"PNG");
	HGLOBAL handle = LoadResource(core_api::get_my_instance(), rsrc);
	DWORD size = SizeofResource(core_api::get_my_instance(), rsrc);
	LPVOID ptr = LockResource(handle);
	if (ptr && size)
	{
		p_out.append_fromptr((t_uint8*)ptr, size);
		ret = true;
	}
	FreeResource(handle);
	return ret;
}
Beispiel #18
0
	virtual HRESULT STDMETHODCALLTYPE Stat( 
		/* [out] */ __RPC__out STATSTG *pstatstg,
		/* [in] */ DWORD grfStatFlag)
	{
		memset(pstatstg, 0, sizeof(STATSTG));
		pstatstg->cbSize.QuadPart = m_data.get_size();
		pstatstg->type = STGTY_STREAM;
		pstatstg->pwcsName = NULL;
		/*if (!(grfStatFlag & STATFLAG_NONAME))
		{
		if (pstatstg->pwcsName = (LPOLESTR)CoTaskMemAlloc(1*2))
		wcscpy_s(pstatstg->pwcsName, 5, L"AB.jpg");
		}*/
		return S_OK;
	}
Beispiel #19
0
	//void readboxfull(service_ptr_t<file> & p_file, abort_callback & p_abort)
	//{
	//	readbox(p_file, p_abort);
	//	p_file->skip(4, p_abort);
	//}
	void readdata(stream_reader * p_file, abort_callback & p_abort)
	{
		m_data.set_size(pfc::downcast_guarded<t_size>(get_data_size()));
		p_file->read(m_data.get_ptr(), m_data.get_size(), p_abort);
	}
bool script_preprocessor::expand_var(pfc::array_t<wchar_t> & out)
{
    typedef pfc::string8_fast (*t_func)();

    enum {
        KStateInNormal,
        KStateInPercent,
    };

    struct {
        const wchar_t * which;
        t_func func;
    } expand_table[] = {
        { L"fb2k_path", helpers::get_fb2k_path },
        { L"fb2k_component_path", helpers::get_fb2k_component_path },
        { L"fb2k_profile_path", helpers::get_profile_path },
    };

    pfc::array_t<wchar_t> buffer;

    wchar_t * pscan = out.get_ptr();
    const wchar_t * pready = NULL;
    const t_size delta = 32;

    int state = KStateInNormal;

    while (*pscan)
    {
        switch (state)
        {
        case KStateInNormal:
            if (*pscan == '%')
            {
                pready = pscan;
                state = KStateInPercent;
            }
            else
            {
                buffer.append_single(*pscan);
            }
            break;

        case KStateInPercent:
            if (*pscan == '%')
            {
                unsigned count = pscan - pready - 1;

                if (!count)
                {
                    buffer.append_single('%');
                }
                else
                {
                    bool found = false;

                    for (t_size i = 0; i < _countof(expand_table); ++i)
                    {
                        t_size expand_which_size = wcslen(expand_table[i].which);

                        if (wcsncmp(pready + 1, expand_table[i].which, max(count, expand_which_size)) == 0)
                        {
                            pfc::stringcvt::string_wide_from_utf8_fast expanded(expand_table[i].func());
                            t_size expanded_count = expanded.length();

                            buffer.append_fromptr(expanded.get_ptr(), expanded_count);
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        buffer.append_fromptr(pready, count);
                    }
                }

                state = KStateInNormal;
            }
            break;
        }

        ++pscan;
    }

    if (state == KStateInPercent)
    {
        buffer.append_fromptr(pscan, wcslen(pscan));
    }

    // trailing 'zero'
    buffer.append_single(0);
    // Copy
    out = buffer;
    return true;
}
Beispiel #21
0
	const void * get_ptr() const {return m_data.get_ptr();} ;
Beispiel #22
0
	virtual HRESULT STDMETHODCALLTYPE Clone( 
		/* [out] */ __RPC__deref_out_opt IStream **ppstm)
	{
		*ppstm = new IStream_memblock_v2<IStream>(m_data.get_ptr(), m_data.get_size());
		return S_OK;
	}
Beispiel #23
0
	IStream_memblock_v2(const t_uint8 * p_data, t_size size) : refcount(0), m_position(0) {m_data.append_fromptr(p_data, size);};
Beispiel #24
0
unsigned playlist_view::get_column_widths(pfc::array_t<int, pfc::alloc_fast_aggressive> & out) const
{
	const bit_array & p_mask = g_cache.active_get_columns_mask();
	unsigned n,t = columns.get_count(),nw=0,i;

	unsigned ac = 0;
	for (n=0;n<t;n++) if  (p_mask[n]) ac++;

	out.set_size(ac);

	RECT hd;
	SetRectEmpty(&hd);
	
	if (cfg_nohscroll && wnd_playlist && GetClientRect(wnd_playlist, &hd))
	{

		int tw=0,total_parts=0;

		pfc::array_t<unsigned> columns_parts;
		
		columns_parts.set_size(t);

		out.fill(0);

		for (n=0,i=0;n<t;n++)
		if (p_mask[n])
		{
			tw += columns[n]->width;
			unsigned part = columns[n]->parts;
			total_parts += part;
			columns_parts[n] = part;
			i++;
		}

		int excess = hd.right-hd.left-tw;

		bool first_pass = true;

		while ( (excess && total_parts) || first_pass)
		{
			first_pass= false;
			int parts = total_parts;


			for (n=0,i=0;n<t;n++)
			if (p_mask[n])
			{
				int part = columns_parts[n];
				int e = ((parts && part) ?  MulDiv(part,(excess),parts) : 0);
				int f = columns[n]->width;

				parts -= part;
				excess -= e;
				if (e < f*-1)
				{
					e = f*-1;
					total_parts -= columns_parts[n];
					columns_parts[n]=0;
				}
				int w = f + e;

				out[i++] += w;
				nw += w;
			}
		}
	}
	else
	{
		for (n=0,i=0;n<t;n++) 
		{
			if (p_mask[n])
			{
				out[i] = columns[n]->width;
				nw += out[i++];
			}
		}
	}
	return nw;
}
Beispiel #25
0
	t_size get_size() const {return m_data.get_size();};