int ParserMpeg2Video::parsePayload(unsigned char* data, int length) {
    // lookup sequence start code
    int o = findStartCode(data, length, 0, MPEG2_SEQUENCE_START);

    if(o >= 0) {
        // skip sequence start code
        o += 4;

        // parse picture sequence (width, height, aspect, duration)
        parseSequenceStart(data + o, length - 4);
    }

    // just to be sure, exit if there's isn't any duration
    if(m_duration == 0) {
        return length;
    }

    // check for picture start codes
    int s = findStartCode(data, length, 0, MPEG2_PICTURE_START);

    // abort if there isn't any picture information
    if(s == -1) {
        return length;
    }

    int e = findStartCode(data, length, s + 4, MPEG2_PICTURE_START);
    o = s;
    s = 0;

    // divide this packet into frames
    while(e != -1) {

        // parse and send payload data
        m_frameType = parsePicture(data + o, e - o);
        Parser::sendPayload(data + s, e - s);

        // get next picture offsets
        s = e;
        o = s;
        e = findStartCode(data, length, s + 4, MPEG2_PICTURE_START);

        // increment timestamps
        m_curPts = DVD_NOPTS_VALUE;
        m_curDts = PtsAdd(m_curDts, m_duration);
    }

    // append last part
    m_frameType = parsePicture(data + o, length - o);
    Parser::sendPayload(data + s, length - s);

    return length;
}
Example #2
0
void BatchSyncMetadata::parseList()
{
    if (!d->everStarted)
    {
        QString message;

        if (d->direction == WriteFromDatabaseToFile)
        {
            message = i18n("Synchronizing image metadata with database. Please wait...");
        }
        else
        {
            message = i18n("Updating database from image metadata. Please wait...");
        }

        emit signalProgressBarMode(StatusProgressBar::CancelProgressBarMode, message);

        d->everStarted = true;
    }

    d->running = true;

    while (d->imageInfoIndex != d->imageInfoList.size() && !d->cancel)
    {
        parsePicture();
        kapp->processEvents();
    }

    d->running = false;

    if (d->cancel ||
        (d->imageInfoJob && !d->imageInfoJob->isRunning()) ||
        !d->imageInfoJob
       )
    {
        complete();
    }
}
Example #3
0
	/// The first coded picture in a group of pictures is an I-Picture. 
	/// The order of the pictures in the coded stream is the order in 
	/// which the decoder processes them in normal play. In particular, 
	/// adjacent B-Pictures in the coded stream are in display order. 
	/// The last coded picture, in display order, of a group of pictures 
	/// is either an I-Picture or a P-Picture.
	void Decoder::parseGroupOfPictures()
	{
		m_input->skipBits(32);	// groupStartCode
		m_input->skipBits(25);	// timeCode
		bool closedGop = m_input->getBool();
		m_input->getBool(); // brokenLink

		nextStartCode();

		if (m_input->nextBits(32) == ExtensionStartCode) 
		{
			m_input->getBits(32);

			while (m_input->nextBits(24) != StartCode) 
			{
				m_input->getBits(8);	// groupExtensionData
			}

			nextStartCode();
		}

		if (m_input->nextBits(32) == UserDataStartCode) 
		{
			m_input->getBits(32);

			while (m_input->nextBits(24) != StartCode) 
			{
				m_input->getBits(8); // userData
			}

			nextStartCode();
		}

		// Reset picture store indexes
		if (closedGop) 
		{
			m_previous = m_future = -1;
		}

		do 
		{
			parsePicture();

    		// Send picture to player
			m_renderer->pushPicture(m_currentPicture, m_pictureCodingType);
			
			// Store current picture in Previous or Future Picture Store
    		// Refer to section 2-D.2.4
			if (m_pictureCodingType == VideoPicture::PictureCodingI || m_pictureCodingType == VideoPicture::PictureCodingP) 
			{
           		if (m_previous == -1)
           		{
           			m_previous = m_current;
           		}
           		else if (m_future == -1)
           		{
           			m_future = m_current;
           		}
           		else
           		{
           			m_future = m_current;
           		}

           		m_current = (m_current + 1) % 3;
			}
			m_currentPicture = m_videoPictureStore[m_current];
			if(m_previous >= 0) 
				m_previousPicture = m_videoPictureStore[m_previous];
			if(m_future >= 0) 
				m_futurePicture = m_videoPictureStore[m_future];

		} while (m_input->nextBits(32) == PictureStartCode);
	}