Exemple #1
0
AVMediaType LibavSingleton::findPacketType(const AVFormatContext *formatContext,
        const AVPacket *packet) const {

    if (NULL == formatContext) {

        throw IllegalArgumentException(
                "The supplied format context for findPacketType(AVFormatContext*,AVPacket*) cannot be null.");
    }

    if (NULL == packet) {

        throw IllegalArgumentException(
                "The supplied packet for findPacketType(AVFormatContext*,AVPacket*) cannot be null.");
    }

    int packetIndex = packet->stream_index;
    int streamNumber = formatContext->nb_streams;

    // Check to make sure the packet index isn't out of bounds.
    if (0 <= packetIndex && streamNumber < packetIndex) {

        stringstream errorMessage;

        errorMessage
        << "Packet index greater than stream number. Packet index: "
                << packetIndex << " Stream number: "
                << streamNumber << " File name: "
                << formatContext->filename << endl;

        throw IllegalStateException(errorMessage.str());
    }

    return findStreamType(formatContext->streams[packetIndex]);
}
int DirectShowPlayerService::findStreamTypes(IBaseFilter *source) const
{
    QVarLengthArray<IBaseFilter *, 16> filters;
    source->AddRef();
    filters.append(source);

    int streamTypes = 0;

    while (!filters.isEmpty()) {
        IEnumPins *pins = 0;
        IBaseFilter *filter = filters[filters.size() - 1];
        filters.removeLast();

        if (SUCCEEDED(filter->EnumPins(&pins))) {
            for (IPin *pin = 0; pins->Next(1, &pin, 0) == S_OK; pin->Release()) {
                PIN_DIRECTION direction;
                if (pin->QueryDirection(&direction) == S_OK && direction == PINDIR_OUTPUT) {
                    AM_MEDIA_TYPE connectionType;
                    if (SUCCEEDED(pin->ConnectionMediaType(&connectionType))) {
                        IPin *peer = 0;

                        if (connectionType.majortype == MEDIATYPE_Audio) {
                            streamTypes |= AudioStream;
                        } else if (connectionType.majortype == MEDIATYPE_Video) {
                            streamTypes |= VideoStream;
                        } else if (SUCCEEDED(pin->ConnectedTo(&peer))) {
                            PIN_INFO peerInfo;
                            if (SUCCEEDED(peer->QueryPinInfo(&peerInfo)))
                                filters.append(peerInfo.pFilter);
                            peer->Release();
                        }
                    } else {
                        streamTypes |= findStreamType(pin);
                    }
                }
            }
        }
        filter->Release();
    }
    return streamTypes;
}