/**********************************************************\ 
Original Author: Richard Bateman and Georg Fritzsche 

Created:    December 3, 2009
License:    Dual license model; choose one of two:
            New BSD License
            http://www.opensource.org/licenses/bsd-license.php
            - or -
            GNU Lesser General Public License, version 2.1
            http://www.gnu.org/licenses/lgpl-2.1.html

Copyright 2009 Georg Fritzsche,
               Firebreath development team
\**********************************************************/

#include <string>
#include <sstream>
#include <vfwmsgs.h>
#include "error_mapping.h"

std::string mapVfwError(HRESULT hr)
{
#define ENTRY(X) case X: err = #X; break;
    std::string err;
    switch(hr)
    {
        default: "<unknown>";
        ENTRY(E_PROP_ID_UNSUPPORTED);
        ENTRY(E_PROP_SET_UNSUPPORTED);
        ENTRY(VFW_E_ADVISE_ALREADY_SET);
        ENTRY(VFW_E_ALREADY_CANCELLED);
        ENTRY(VFW_E_ALREADY_COMMITTED);
        ENTRY(VFW_E_ALREADY_CONNECTED);
        ENTRY(VFW_E_BAD_KEY);
        ENTRY(VFW_E_BAD_VIDEOCD);
        ENTRY(VFW_E_BADALIGN);
        ENTRY(VFW_E_BUFFER_NOTSET);
        ENTRY(VFW_E_BUFFER_OVERFLOW);
        ENTRY(VFW_E_BUFFER_UNDERFLOW);
        ENTRY(VFW_E_BUFFERS_OUTSTANDING);
        ENTRY(VFW_E_CANNOT_CONNECT);
        ENTRY(VFW_E_CANNOT_LOAD_SOURCE_FILTER);
        ENTRY(VFW_E_CANNOT_RENDER);
        ENTRY(VFW_E_CERTIFICATION_FAILURE);
        ENTRY(VFW_E_CHANGING_FORMAT);
        ENTRY(VFW_E_CIRCULAR_GRAPH);
        ENTRY(VFW_E_COLOR_KEY_SET);
        ENTRY(VFW_E_COPYPROT_FAILED);
        ENTRY(VFW_E_CORRUPT_GRAPH_FILE);
        ENTRY(VFW_E_DDRAW_CAPS_NOT_SUITABLE);
        ENTRY(VFW_E_DDRAW_VERSION_NOT_SUITABLE);
        ENTRY(VFW_E_DUPLICATE_NAME);
        ENTRY(VFW_E_DVD_CMD_CANCELLED);
        ENTRY(VFW_E_DVD_DECNOTENOUGH);
        ENTRY(VFW_E_DVD_GRAPHNOTREADY);
        ENTRY(VFW_E_DVD_INCOMPATIBLE_REGION);
        ENTRY(VFW_E_DVD_INVALID_DISC);
        ENTRY(VFW_E_DVD_INVALIDDOMAIN);
        ENTRY(VFW_E_DVD_LOW_PARENTAL_LEVEL);
        ENTRY(VFW_E_DVD_MENU_DOES_NOT_EXIST);
        ENTRY(VFW_E_DVD_NO_ATTRIBUTES);
        ENTRY(VFW_E_DVD_NO_BUTTON);
        ENTRY(VFW_E_DVD_NO_GOUP_PGC);
        ENTRY(VFW_E_DVD_NO_RESUME_INFORMATION);
        ENTRY(VFW_E_DVD_NOT_IN_KARAOKE_MODE);
        ENTRY(VFW_E_DVD_OPERATION_INHIBITED);
        ENTRY(VFW_E_DVD_RENDERFAIL);
        ENTRY(VFW_E_DVD_STATE_CORRUPT);
        ENTRY(VFW_E_DVD_STATE_WRONG_DISC);
        ENTRY(VFW_E_DVD_STATE_WRONG_VERSION);
        ENTRY(VFW_E_DVD_STREAM_DISABLED);
        ENTRY(VFW_E_DVD_TITLE_UNKNOWN);
        ENTRY(VFW_E_DVD_VMR9_INCOMPATIBLEDEC);
        ENTRY(VFW_E_DVD_WRONG_SPEED);
        ENTRY(VFW_E_ENUM_OUT_OF_RANGE);
        ENTRY(VFW_E_ENUM_OUT_OF_SYNC);
        ENTRY(VFW_E_FILE_TOO_SHORT);
        ENTRY(VFW_E_FILTER_ACTIVE);
        ENTRY(VFW_E_FRAME_STEP_UNSUPPORTED);
        ENTRY(VFW_E_IN_FULLSCREEN_MODE);
        ENTRY(VFW_E_INVALID_CLSID);
        ENTRY(VFW_E_INVALID_DIRECTION);
        ENTRY(VFW_E_INVALID_FILE_FORMAT);
        ENTRY(VFW_E_INVALID_FILE_VERSION);
        ENTRY(VFW_E_INVALID_MEDIA_TYPE);
        ENTRY(VFW_E_INVALID_RECT);
        ENTRY(VFW_E_INVALIDMEDIATYPE);
        ENTRY(VFW_E_INVALIDSUBTYPE);
        ENTRY(VFW_E_MEDIA_TIME_NOT_SET);
        ENTRY(VFW_E_MONO_AUDIO_HW);
        ENTRY(VFW_E_MPEG_NOT_CONSTRAINED);
        ENTRY(VFW_E_NEED_OWNER);
        ENTRY(VFW_E_NO_ACCEPTABLE_TYPES);
        ENTRY(VFW_E_NO_ADVISE_SET);
        ENTRY(VFW_E_NO_ALLOCATOR);
        ENTRY(VFW_E_NO_AUDIO_HARDWARE);
        ENTRY(VFW_E_NO_CAPTURE_HARDWARE);
        ENTRY(VFW_E_NO_CLOCK);
        ENTRY(VFW_E_NO_COLOR_KEY_FOUND);
        ENTRY(VFW_E_NO_COLOR_KEY_SET);
        ENTRY(VFW_E_NO_DECOMPRESSOR);
        ENTRY(VFW_E_NO_DISPLAY_PALETTE);
        ENTRY(VFW_E_NO_FULLSCREEN);
        ENTRY(VFW_E_NO_INTERFACE);
        ENTRY(VFW_E_NO_MODEX_AVAILABLE);
        ENTRY(VFW_E_NO_PALETTE_AVAILABLE);
        ENTRY(VFW_E_NO_SINK);
        ENTRY(VFW_E_NO_TIME_FORMAT);
        ENTRY(VFW_E_NO_TIME_FORMAT_SET);
        ENTRY(VFW_E_NO_TRANSPORT);
        ENTRY(VFW_E_NO_TYPES);
        ENTRY(VFW_E_NO_VP_HARDWARE);
        ENTRY(VFW_E_NOT_ALLOWED_TO_SAVE);
        ENTRY(VFW_E_NOT_COMMITTED);
        ENTRY(VFW_E_NOT_CONNECTED);
        ENTRY(VFW_E_NOT_FOUND);
        ENTRY(VFW_E_NOT_IN_GRAPH);
        ENTRY(VFW_E_NOT_OVERLAY_CONNECTION);
        ENTRY(VFW_E_NOT_PAUSED);
        ENTRY(VFW_E_NOT_RUNNING);
        ENTRY(VFW_E_NOT_SAMPLE_CONNECTION);
        ENTRY(VFW_E_NOT_STOPPED);
        ENTRY(VFW_E_OUT_OF_VIDEO_MEMORY);
        ENTRY(VFW_E_PALETTE_SET);
        ENTRY(VFW_E_PIN_ALREADY_BLOCKED);
        ENTRY(VFW_E_PIN_ALREADY_BLOCKED_ON_THIS_THREAD);
        ENTRY(VFW_E_PROCESSOR_NOT_SUITABLE);
        ENTRY(VFW_E_READ_ONLY);
        ENTRY(VFW_E_RPZA);
        ENTRY(VFW_E_RUNTIME_ERROR);
        ENTRY(VFW_E_SAMPLE_REJECTED);
        ENTRY(VFW_E_SAMPLE_REJECTED_EOS);
        ENTRY(VFW_E_SAMPLE_TIME_NOT_SET);
        ENTRY(VFW_E_SIZENOTSET);
        ENTRY(VFW_E_START_TIME_AFTER_END);
        ENTRY(VFW_E_STATE_CHANGED);
        ENTRY(VFW_E_TIME_ALREADY_PASSED);
        ENTRY(VFW_E_TIME_EXPIRED);
        ENTRY(VFW_E_TIMEOUT);
        ENTRY(VFW_E_TOO_MANY_COLORS);
        ENTRY(VFW_E_TYPE_NOT_ACCEPTED);
        ENTRY(VFW_E_UNKNOWN_FILE_TYPE);
        ENTRY(VFW_E_UNSUPPORTED_AUDIO);
        ENTRY(VFW_E_UNSUPPORTED_STREAM);
        ENTRY(VFW_E_UNSUPPORTED_VIDEO);
        ENTRY(VFW_E_VMR_NO_AP_SUPPLIED);
        ENTRY(VFW_E_VMR_NO_DEINTERLACE_HW);
        ENTRY(VFW_E_VMR_NOT_IN_MIXER_MODE);
        ENTRY(VFW_E_VP_NEGOTIATION_FAILED);
        ENTRY(VFW_E_WRONG_STATE);
        ENTRY(VFW_S_AUDIO_NOT_RENDERED);
        ENTRY(VFW_S_CANT_CUE);
        ENTRY(VFW_S_CONNECTIONS_DEFERRED);
        ENTRY(VFW_S_DUPLICATE_NAME);
        ENTRY(VFW_S_DVD_CHANNEL_CONTENTS_NOT_AVAILABLE);
        ENTRY(VFW_S_DVD_NON_ONE_SEQUENTIAL);
        ENTRY(VFW_S_DVD_NOT_ACCURATE);
        ENTRY(VFW_S_ESTIMATED);
        ENTRY(VFW_S_MEDIA_TYPE_IGNORED);
        ENTRY(VFW_S_NO_MORE_ITEMS);
        ENTRY(VFW_S_NO_STOP_TIME);
        ENTRY(VFW_S_NOPREVIEWPIN);
        ENTRY(VFW_S_PARTIAL_RENDER);
        ENTRY(VFW_S_RESERVED);
        ENTRY(VFW_S_RESOURCE_NOT_NEEDED);
        ENTRY(VFW_S_RPZA);
        ENTRY(VFW_S_SOME_DATA_IGNORED);
        ENTRY(VFW_S_STATE_INTERMEDIATE);
        ENTRY(VFW_S_STREAM_OFF);
        ENTRY(VFW_S_VIDEO_NOT_RENDERED);
    }
#undef ENTRY
    
    std::ostringstream ss;
    ss << err << " (0x" << (void*)hr << ")";
    return ss.str();
}
