Exemplo n.º 1
0
bool baseStructureParser<streamT>::readUntil(bool inTerm, const char* termChars, int numTermChars,
        char& termHit, string& result) {
    result = "";
    // Outer loop that keeps reading more chunks of size bufSize from the file
    while(1) {
        //cout << "        ru: bufIdx="<<bufIdx<<", bufSize="<<bufSize<<endl;
        // Iterate through the rest of the file looking for terminator chars
        while(bufIdx<dataInBuf) {
            for(int i=0; i<numTermChars; i++) {
                // If the current character in buf is a terminator, return the result
                if(isMember(buf[bufIdx], termChars, numTermChars)) {
                    if(inTerm) {
                        termHit=buf[bufIdx];
                        return true;
                    }
                } else {
                    if(!inTerm) {
                        termHit=buf[bufIdx];
                        return true;
                    }
                }
            }
            // If the current character in buf is a terminator, return the result
            if(!inTerm) {
                termHit=buf[bufIdx];
                //nextChar();
                return true;
            }
            // If the character is not a terminator, append it to ret
            result += buf[bufIdx];
            bufIdx++;
        }

        //cout << "        ru: feof(f)="<<feof(f)<<", ferror(f)="<<ferror(f)<<endl;

        // If we've reached the end of the file, return unsuccessfuly
        if(streamEnd()) return false;

        // If we've encountered an error, yell
        if(streamError()) {
            fprintf(stderr, "ERROR reading file!");
//      exit(-1);
        }

        nextChar();
    }
}
Exemplo n.º 2
0
void Bioscope::frame(QImage * img)
{
    AVPacket packet;
    int done = 0;

    int accum_duration = 0;

    while (av_read_frame(m_detail->formatContext, &packet) >= 0) {
        if (packet.stream_index == m_detail->vStreamIndex) {

            accum_duration += packet.duration;

            avcodec_decode_video2(
                        m_detail->codecContext,
                        m_detail->frame,
                        &done,
                        &packet);
            if (done) {
                /* if frame isn't compatible - change it */
                if (img->width() != m_detail->width
                        || img->height() != m_detail->height
                        || img->format() != QImage::Format_RGB888) {
                    *img = QImage(m_detail->width, m_detail->height, QImage::Format_RGB888  );
                }

                avpicture_fill((AVPicture *)m_detail->frameRGB,
                               (uint8_t*) img->bits(),
                               PIX_FMT_RGB24,
                               img->width(),
                               img->height());

                sws_scale(m_detail->convertContext,
                          m_detail->frame->data, m_detail->frame->linesize, 0,
                          m_detail->codecContext->height,
                          m_detail->frameRGB->data, m_detail->frameRGB->linesize);

                m_detail->last_pts += accum_duration;

                return;
            }
        }
    }

    emit streamEnd();
}