'QT4'에 해당되는 글 19건

  1. 2012.11.09 크로스플랫폼 시리얼 라이브러리 - qtextserialport
  2. 2011.07.26 [s3c6410] 터치 판넬 상하 위치 변경
  3. 2011.07.06 [qt4] read mpeg4 stream from network IP cam
  4. 2011.07.04 [qt4] QFileSystemModel 경로 설정하기
  5. 2011.06.24 [qt4] 일정 시점에서부터 지정한 시간이 지났는지 체크 - 타이머
  6. 2011.06.15 [s3c6410] libvorbis-1.3.2 cross compile
  7. 2011.06.10 [s3c6410, qt4] glib cross compile
  8. 2011.06.09 [qt4] 디바이스들 초기화 하기
  9. 2011.06.09 [s3c6410] glib-2.2 porting 중 에러 대처
  10. 2011.05.24 qlabel 색 지정하기

크로스플랫폼 시리얼 라이브러리 - qtextserialport

http://code.google.com/p/qextserialport/


qt용 크로스플랫폼 시리얼 프로그래밍 라이브러리


[s3c6410] 터치 판넬 상하 위치 변경

ts_calibration 으로 calibration만 다시 잡아서 수정.

pointercal 파일 위치를 수정 가능한 위치로 변경
/etc/profile 에 TSLIB_CALIBFILE 환경변수로 저장
Qt4에서도 참조할 수 있게 POINTERCAL_FILE 환경변수 지정

[qt4] read mpeg4 stream from network IP cam

  • jvccthread.h
  • #include <QThread>
    #include <QMutex>
    #include <QWaitCondition>
    #include <QBuffer>
    extern "C"
    {
    #include <libavformat/avformat.h>
    #include <libavcodec/avcodec.h>
    #include <libswscale/swscale.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>
    #include <cstdio>
    }
    class jvcMpegThread : public QThread
    {
    Q_OBJECT
    public:
    jvcMpegThread(QByteArray *parent_array=0,unsigned int read_buffer_size=1024,QObject *parent=0);
    void getMpegImage(AVFrame *pFrame, int w, int h,int i);
    int read_packet(uint8_t *buf,int buf_size);

    bool readyForNextPacket;
    protected:
    void run();
    QMutex mutex;
    QWaitCondition condition;
    QBuffer *buf,*dataBuf;
    QByteArray byteArray,*dataArray;
    unsigned intbio_buffer_size;

    signals:
    void newImageSignal(QByteArray *);
    void giveMoreData();
    };
  • jvccthread.cpp
  • #include "jvccthread.h"
    #include <QDebug>
    FILE *pFile = NULL;
    AVFormatContext *pFormatCtx;
    int         i, videoStream;
    AVCodecContext  *pCodecCtx;
    AVCodec     *pCodec;
    AVFrame     *pFrame;
    AVFrame     *pFrameRGB;
    AVPacket    packet;
    int         frameFinished;
    int         numBytes;
    uint8_t     *buffer;
    unsigned char   *bio_buffer;
    AVInputFormat   *fmt;
    AVFormatParameters ap;
    ByteIOContext *io;
    static struct SwsContext *img_convert_ctx;

    static int read_packets(void *opaque,uint8_t *buf,int buf_size)
    {
    jvcMpegThread *mp=(jvcMpegThread *)opaque;
    int ret=mp->read_packet(buf,buf_size);
    //Debug("HRE");
       // int ret = fread(buf, 1, buf_size, pFile);
    return ret;
    }
    jvcMpegThread::jvcMpegThread(QByteArray *parent_array,unsigned int read_buffer_size,QObject *parent)
        :QThread(parent),dataArray(parent_array),bio_buffer_size(read_buffer_size)
    {
    buf=new QBuffer(&byteArray);
    //data=new QDataStream(buf);
    buf->open(QIODevice::WriteOnly);
    dataBuf=new QBuffer(dataArray);
    dataBuf->open(QIODevice::ReadWrite);
    readyForNextPacket=false;
       // QThread::start(QThread::LowPriority);

    }

    void jvcMpegThread::getMpegImage(AVFrame *pFrame, int w, int h,int i)
    {
    int  y,x;
     //byteArray.clear();
     buf->seek(0);
     buf->write(QString("P6\n"+QString::number(w)+" "+QString::number(h)+"\n255\n").toLatin1().data());

    // Write pixel data
    for(y=0; y<h; y++)
    {
        buf->write((char *)(pFrame->data[0]+y*pFrame->linesize[0]),w*3);
    }
    emit newImageSignal(&byteArray);
    }

    void jvcMpegThread::run()
    {
       // mutex.lock();

      //  mutex.unlock();
    //pFile = fopen("test.mpg", "rb");
    av_register_all();

    fmt=av_find_input_format("m4v");

    fmt->flags |= AVFMT_NOFILE|AVFMT_FLAG_IGNIDX;
    //bio_buffer_size=61440;
    bio_buffer=(unsigned char *)av_malloc(bio_buffer_size);
    io=new ByteIOContext;
    io->is_streamed=1;

    int ret = init_put_byte(io, bio_buffer, bio_buffer_size, 0, this, read_packets, NULL, NULL);
    if (av_open_input_stream(&pFormatCtx, io, "", fmt, NULL)!=0)
        return;
    qDebug("Stream Opened");
    if(av_find_stream_info(pFormatCtx)<0)
    {
        qDebug("Stream Info Error");
        return;
    }//qDebug("Stream Info Error"); // Couldn't find stream information
       qDebug("Stream Finded");
    // dump_format(pFormatCtx, 0, "test.mpg", false);

    videoStream=-1;
    for(i=0; i<pFormatCtx->nb_streams; i++)
        if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO)
        {
            videoStream=i;
            break;
        }
    if(videoStream==-1)
        return;// Didn't find a video strea
    qDebug()<<"Codec Finded"<<videoStream;

    // Get a pointer to the codec context for the video stream
    pCodecCtx=pFormatCtx->streams[videoStream]->codec;

    // Find the decoder for the video stream
    pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
    if(pCodec==NULL)
        qDebug("Codec Error"); // Codec not found

    // Open codec
    if(avcodec_open(pCodecCtx, pCodec)<0)
        qDebug("Codec Open Error"); // Could not open codec

    // Hack to correct wrong frame rates that seem to be generated by some codecs
      //  if(pCodecCtx->time_base.num>1000 && pCodecCtx->time_base.den==1)
      //      pCodecCtx->time_base.den=1000;

    // Allocate video frame
    pFrame=avcodec_alloc_frame();

    // Allocate an AVFrame structure
    pFrameRGB=avcodec_alloc_frame();
    if(pFrameRGB==NULL)
        qDebug("Error");

    // Determine required buffer size and allocate buffer
    numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height);
    qDebug()<<numBytes;
    buffer=(uint8_t *)malloc(numBytes);

    // Assign appropriate parts of buffer to image planes in pFrameRGB
    avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
        pCodecCtx->width, pCodecCtx->height);

    // Read frames and save first five frames to disk
    i=0;
    int w = pCodecCtx->width;
    int h = pCodecCtx->height;
    int dst_w=800;
    int dst_h=600;

    img_convert_ctx = sws_getContext(pCodecCtx->width,pCodecCtx->height,pCodecCtx->pix_fmt,pCodecCtx->width,pCodecCtx->height, PIX_FMT_RGB24, SWS_BICUBIC,NULL, NULL, NULL);
    while (av_read_frame(pFormatCtx, &packet)>=0)
        {

          // Is this a packet from the video stream?
        if(packet.stream_index==videoStream)
        {

            // Decode video frame
            avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
                packet.data, packet.size);

            // Did we get a video frame?
            if(frameFinished)
            {
                    sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
                    i++;
                    getMpegImage(pFrameRGB, pCodecCtx->width, pCodecCtx->height,i);
            }
        }

        // Free the packet that was allocated by av_read_frame
        av_free_packet(&packet);
        }

    }
    int jvcMpegThread::read_packet(uint8_t *buf,int buf_size)
    {
    emit giveMoreData();
    while (!readyForNextPacket)
    {
           // qDebug("Waiting for READ");
        this->msleep(1);
    }
    readyForNextPacket=false;
    dataBuf->seek(0);
    qint64 ret=dataBuf->read((char *)buf,buf_size);
    return ret;

    }
  • mpeggstream.h
  • #include "jvccthread.h"
    #include <QTcpSocket>
    class mpegStream : public QObject
    {
    Q_OBJECT
    public:
    mpegStream(QTcpSocket *parent=0);
    public slots:
    void startStopThread(bool);
    private slots:
    void readDataStream();



    signals:
    //void newImageSignal(QByteArray *);
    void newDataForDecode(uint);
    void newDataSignal(QByteArray *);
    private:
    QByteArray block,dataArray;
    uchar *frame;
    int blockcount;
    jvcMpegThread *th;
    unsigned int read_buffer_size;
    int wait_interval;
    QTcpSocket *socket;
    };
  • mpeggstream.cpp
  • #include "mpegstream.h"


    mpegStream::mpegStream(QTcpSocket *parent)
    :socket(parent)
    {
    //file=new QFile;
    //file->open(QIODevice::ReadOnly);
    blockcount=0;
    read_buffer_size=61440/2;
    th=new jvcMpegThread(&dataArray,read_buffer_size);
    connect(th,SIGNAL(newImageSignal(QByteArray*)),this,SIGNAL(newDataSignal(QByteArray*)));
    connect(th,SIGNAL(giveMoreData()),this,SLOT(readDataStream()));
    connect(this,SIGNAL(newDataForDecode(uint)),th,SLOT(getPacket(uint)));
    block.clear();


    }

    void mpegStream::readDataStream()
    {
    //qDebug()<<block.data();
    if (socket->bytesAvailable()>200000) qDebug()<<socket->bytesAvailable();
     while (block.size()<read_buffer_size)
        {
        //qDebug()<<"Entering While"<<socket->bytesAvailable()<<block.size();
            if (socket->bytesAvailable()==0)
            {
                socket->waitForReadyRead(3000);
             //   qDebug()<<block.data();
               // qDebug("Bytes Available 0");
            }
            if (socket->bytesAvailable()+block.size()<read_buffer_size)

                block.append(socket->readAll());
            else
            {
                if (block.size()>0 && block.size()<read_buffer_size) block.append(socket->read(read_buffer_size-block.size()));
                //else if (block.size()==61 440) readyForDecode=true;
                else block=socket->read(read_buffer_size);
            }
        }
        dataArray=block;
        th->readyForNextPacket=true;
      //  qDebug()<<block.data();
        block.clear();
    }

    void mpegStream::startStopThread(bool b)
    {
    if (b) th->start(QThread::LowPriority);
        else
       {
        th->terminate();
        th->wait(100);
    }
    }


[qt4] QFileSystemModel 경로 설정하기

QFilSystemModel을 생성하고 setRootPath()을 사용해서 표시하고자 하는 경로을 입력해도 실제
화면에 보여지는 경로는 "/"을 표시한다.
그냥 QFileSystemModel 객체를 뷰위젯에 연결하면 안되고, 중간에 QModelIndex을 통해서 뷰위젯에 연결해
줘야 표시하고자 하는 디렉토리를 표시할 수 있다.
ex)
QFileSystemModel *model_app;
model_app = new QFileSystemModel(this);

QModelIndexl model_idx = model_app->setRootPath("/app");

QTreeView *treeview_app;
treeview_app = new QTreeView( this );
treeview_app->setModel( model_app );
treeview_app->setRootIndex( model_idx );


[qt4] 일정 시점에서부터 지정한 시간이 지났는지 체크 - 타이머

void testTime::start()
{
    QTime testtime;
    testime = QTime::currentTime();
    testtime.start();
}

bool testTime::chkTime()
{
    if ( testtime.elapsed() > 2000 )
        return false;
    return true;

}


[s3c6410] libvorbis-1.3.2 cross compile

./configure --prefix=/usr/arm-generic-linux-gnueabi --host=arm-generic-linux-gnueabi --with-ogg-libraries=/usr/arm-generic-linux-gnueabi/lib
make && make install

'임베디드 > S3C6410' 카테고리의 다른 글

[s3c6410] gstreamer test  (0) 2011.06.22
[s3c6410] libxml2 cross compile  (0) 2011.06.20
[s3c641] libogg cross compile  (0) 2011.06.15
[s3c6410] gst-plugins-base-0.10.22 cross compile  (0) 2011.06.14
[s3c6410, qt4] glib cross compile  (0) 2011.06.10

[s3c6410, qt4] glib cross compile

glib은 libffi 라이브러리를 요구한다. 다운로드

arm-linux.cache 파일 작성

내용은 아래와 같이 한다.

glib_cv_long_long_format=ll
glib_cv_stack_grows=no
glib_cv_has__inline=yes
glib_cv_has__inline__=yes
glib_cv_uscore=no
ac_cv_func_posix_getpwuid_r=yes
ac_cv_func_posix_getgrgid_r=yes
glib_cv_use_pid_surrogate=yes

glib-2.22.0 configure options

./configure --prefix=/usr/arm-generic-linux-gnueabi --target=arm-generic-linux-gnueabi --cache-file=arm-linux.cache --with-threads=posix --host=arm-generic-linux-gnueabi

make

make install


glib-2.26.1 configure options

PKG_CONFIG="/usr/arm-generic-linux-gnueabi/bin/pkg-config" ./configure --prefix=$PWD/_install --target=arm-generic-linux-gnueabi --cache-file=arm-linux.cache --with-threads=posix --host=arm-generic-linux-gnueabi


* SSIZE_MAX error가 발생하면 해당 파일을 열어서 아래와 같이 추가한다.

#ifndef SSIZE_MAX

#define SSIZE_MAX        LONG_MAX

#endif

'임베디드 > S3C6410' 카테고리의 다른 글

[s3c641] libogg cross compile  (0) 2011.06.15
[s3c6410] gst-plugins-base-0.10.22 cross compile  (0) 2011.06.14
[s3c6410] glib-2.2 porting 중 에러 대처  (0) 2011.06.09
[s3c6410] ffmpeg porting  (0) 2011.06.09
[s3c6410] x264 porting  (0) 2011.06.09

[qt4] 디바이스들 초기화 하기

  QWSServer *server = QWSServer::instance();
  if (server)
  {
            QScreen *screen = QScreen::instance();
            screen->shutdownDevice();
            screen->disconnect();
            screen->connect("/dev/fb");
            screen->initDevice();
            server->enablePainting( true );
            server->refresh();
  }

[s3c6410] glib-2.2 porting 중 에러 대처

SSIZE_MAX 에러 일 경우, 에러가 나온 해당 파일을 찾아서 아래와 같은 내용을 첨부한다.
#ifndef SSIZE_MAX
# define SSIZE_MAX LONG_MAX
#endif


'임베디드 > S3C6410' 카테고리의 다른 글

[s3c6410] gst-plugins-base-0.10.22 cross compile  (0) 2011.06.14
[s3c6410, qt4] glib cross compile  (0) 2011.06.10
[s3c6410] ffmpeg porting  (0) 2011.06.09
[s3c6410] x264 porting  (0) 2011.06.09
[s3c6410] usb disk automount rules  (0) 2011.06.03

qlabel 색 지정하기

저번에는 전경색, 또는 배경색 둘 중 하나만 설정 할 수 있는 방법이었지만, 이번 팁은 동시에 라벨 색을 변경할 수 있는 방법이다.

QPalette pl( label->palette() );
pl.setColorgroup( QPalette::Normal, fontColor, pl.button(), pl.light(), pl.dark(), pl.mid(), pl.text(), pl.brightText(), pl.base(), backgroundColor );

label->setPalette( pl );
label->setAutoFillBackground( this );

prev 1 2 next