equal
deleted
inserted
replaced
57 public: |
57 public: |
58 QVideoFramePrivate() |
58 QVideoFramePrivate() |
59 : startTime(-1) |
59 : startTime(-1) |
60 , endTime(-1) |
60 , endTime(-1) |
61 , data(0) |
61 , data(0) |
62 , numBytes(0) |
62 , mappedBytes(0) |
63 , bytesPerLine(0) |
63 , bytesPerLine(0) |
64 , pixelFormat(QVideoFrame::Format_Invalid) |
64 , pixelFormat(QVideoFrame::Format_Invalid) |
65 , fieldType(QVideoFrame::ProgressiveFrame) |
65 , fieldType(QVideoFrame::ProgressiveFrame) |
66 , buffer(0) |
66 , buffer(0) |
67 { |
67 { |
70 QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format) |
70 QVideoFramePrivate(const QSize &size, QVideoFrame::PixelFormat format) |
71 : size(size) |
71 : size(size) |
72 , startTime(-1) |
72 , startTime(-1) |
73 , endTime(-1) |
73 , endTime(-1) |
74 , data(0) |
74 , data(0) |
75 , numBytes(0) |
75 , mappedBytes(0) |
76 , bytesPerLine(0) |
76 , bytesPerLine(0) |
77 , pixelFormat(format) |
77 , pixelFormat(format) |
78 , fieldType(QVideoFrame::ProgressiveFrame) |
78 , fieldType(QVideoFrame::ProgressiveFrame) |
79 , buffer(0) |
79 , buffer(0) |
80 { |
80 { |
87 |
87 |
88 QSize size; |
88 QSize size; |
89 qint64 startTime; |
89 qint64 startTime; |
90 qint64 endTime; |
90 qint64 endTime; |
91 uchar *data; |
91 uchar *data; |
92 int numBytes; |
92 int mappedBytes; |
93 int bytesPerLine; |
93 int bytesPerLine; |
94 QVideoFrame::PixelFormat pixelFormat; |
94 QVideoFrame::PixelFormat pixelFormat; |
95 QVideoFrame::FieldType fieldType; |
95 QVideoFrame::FieldType fieldType; |
96 QAbstractVideoBuffer *buffer; |
96 QAbstractVideoBuffer *buffer; |
97 |
97 |
107 |
107 |
108 A QVideoFrame encapsulates the data of a video frame, and information about the frame. |
108 A QVideoFrame encapsulates the data of a video frame, and information about the frame. |
109 |
109 |
110 The contents of a video frame can be mapped to memory using the map() function. While |
110 The contents of a video frame can be mapped to memory using the map() function. While |
111 mapped the video data can accessed using the bits() function which returns a pointer to a |
111 mapped the video data can accessed using the bits() function which returns a pointer to a |
112 buffer, the total size of which is given by the numBytes(), and the size of each line is given |
112 buffer, the total size of which is given by the mappedBytes(), and the size of each line is given |
113 by bytesPerLine(). The return value of the handle() function may be used to access frame data |
113 by bytesPerLine(). The return value of the handle() function may be used to access frame data |
114 using the internal buffer's native APIs. |
114 using the internal buffer's native APIs. |
115 |
115 |
116 The video data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer. A QVideoFrame |
116 The video data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer. A QVideoFrame |
117 may be constructed from any buffer type by subclassing the QAbstractVideoBuffer class. |
117 may be constructed from any buffer type by subclassing the QAbstractVideoBuffer class. |
302 Constructs a video frame from an \a image. |
302 Constructs a video frame from an \a image. |
303 |
303 |
304 \note This will construct an invalid video frame if there is no frame type equivalent to the |
304 \note This will construct an invalid video frame if there is no frame type equivalent to the |
305 image format. |
305 image format. |
306 |
306 |
307 \sa equivalentPixelFormat() |
307 \sa pixelFormatFromImageFormat() |
308 */ |
308 */ |
309 |
309 |
310 QVideoFrame::QVideoFrame(const QImage &image) |
310 QVideoFrame::QVideoFrame(const QImage &image) |
311 : d(new QVideoFramePrivate( |
311 : d(new QVideoFramePrivate( |
312 image.size(), equivalentPixelFormat(image.format()))) |
312 image.size(), pixelFormatFromImageFormat(image.format()))) |
313 { |
313 { |
314 if (d->pixelFormat != Format_Invalid) |
314 if (d->pixelFormat != Format_Invalid) |
315 d->buffer = new QImageVideoBuffer(image); |
315 d->buffer = new QImageVideoBuffer(image); |
316 } |
316 } |
317 |
317 |
508 |
508 |
509 bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) |
509 bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) |
510 { |
510 { |
511 if (d->buffer != 0 && d->data == 0) { |
511 if (d->buffer != 0 && d->data == 0) { |
512 Q_ASSERT(d->bytesPerLine == 0); |
512 Q_ASSERT(d->bytesPerLine == 0); |
513 Q_ASSERT(d->numBytes == 0); |
513 Q_ASSERT(d->mappedBytes == 0); |
514 |
514 |
515 d->data = d->buffer->map(mode, &d->numBytes, &d->bytesPerLine); |
515 d->data = d->buffer->map(mode, &d->mappedBytes, &d->bytesPerLine); |
516 |
516 |
517 return d->data != 0; |
517 return d->data != 0; |
518 } |
518 } |
519 |
519 |
520 return false; |
520 return false; |
530 */ |
530 */ |
531 |
531 |
532 void QVideoFrame::unmap() |
532 void QVideoFrame::unmap() |
533 { |
533 { |
534 if (d->data != 0) { |
534 if (d->data != 0) { |
535 d->numBytes = 0; |
535 d->mappedBytes = 0; |
536 d->bytesPerLine = 0; |
536 d->bytesPerLine = 0; |
537 d->data = 0; |
537 d->data = 0; |
538 |
538 |
539 d->buffer->unmap(); |
539 d->buffer->unmap(); |
540 } |
540 } |
546 \note This is the bytes per line of the first plane only. The bytes per line of subsequent |
546 \note This is the bytes per line of the first plane only. The bytes per line of subsequent |
547 planes should be calculated as per the frame type. |
547 planes should be calculated as per the frame type. |
548 |
548 |
549 This value is only valid while the frame data is \l {map()}{mapped}. |
549 This value is only valid while the frame data is \l {map()}{mapped}. |
550 |
550 |
551 \sa bits(), map(), numBytes() |
551 \sa bits(), map(), mappedBytes() |
552 */ |
552 */ |
553 |
553 |
554 int QVideoFrame::bytesPerLine() const |
554 int QVideoFrame::bytesPerLine() const |
555 { |
555 { |
556 return d->bytesPerLine; |
556 return d->bytesPerLine; |
559 /*! |
559 /*! |
560 Returns a pointer to the start of the frame data buffer. |
560 Returns a pointer to the start of the frame data buffer. |
561 |
561 |
562 This value is only valid while the frame data is \l {map()}{mapped}. |
562 This value is only valid while the frame data is \l {map()}{mapped}. |
563 |
563 |
564 \sa map(), numBytes(), bytesPerLine() |
564 \sa map(), mappedBytes(), bytesPerLine() |
565 */ |
565 */ |
566 |
566 |
567 uchar *QVideoFrame::bits() |
567 uchar *QVideoFrame::bits() |
568 { |
568 { |
569 return d->data; |
569 return d->data; |
572 /*! |
572 /*! |
573 Returns a pointer to the start of the frame data buffer. |
573 Returns a pointer to the start of the frame data buffer. |
574 |
574 |
575 This value is only valid while the frame data is \l {map()}{mapped}. |
575 This value is only valid while the frame data is \l {map()}{mapped}. |
576 |
576 |
577 \sa map(), numBytes(), bytesPerLine() |
577 \sa map(), mappedBytes(), bytesPerLine() |
578 */ |
578 */ |
579 |
579 |
580 const uchar *QVideoFrame::bits() const |
580 const uchar *QVideoFrame::bits() const |
581 { |
581 { |
582 return d->data; |
582 return d->data; |
583 } |
583 } |
584 |
584 |
585 /*! |
585 /*! |
586 Returns the number of bytes occupied by the frame data. |
586 Returns the number of bytes occupied by the mapped frame data. |
587 |
587 |
588 This value is only valid while the frame data is \l {map()}{mapped}. |
588 This value is only valid while the frame data is \l {map()}{mapped}. |
589 |
589 |
590 \sa map() |
590 \sa map() |
591 */ |
591 */ |
592 |
592 |
593 int QVideoFrame::numBytes() const |
593 int QVideoFrame::mappedBytes() const |
594 { |
594 { |
595 return d->numBytes; |
595 return d->mappedBytes; |
596 } |
596 } |
597 |
597 |
598 /*! |
598 /*! |
599 Returns a type specific handle to a video frame's buffer. |
599 Returns a type specific handle to a video frame's buffer. |
600 |
600 |
647 /*! |
647 /*! |
648 Returns an video pixel format equivalent to an image \a format. If there is no equivalent |
648 Returns an video pixel format equivalent to an image \a format. If there is no equivalent |
649 format QVideoFrame::InvalidType is returned instead. |
649 format QVideoFrame::InvalidType is returned instead. |
650 */ |
650 */ |
651 |
651 |
652 QVideoFrame::PixelFormat QVideoFrame::equivalentPixelFormat(QImage::Format format) |
652 QVideoFrame::PixelFormat QVideoFrame::pixelFormatFromImageFormat(QImage::Format format) |
653 { |
653 { |
654 switch (format) { |
654 switch (format) { |
655 case QImage::Format_Invalid: |
655 case QImage::Format_Invalid: |
656 case QImage::Format_Mono: |
656 case QImage::Format_Mono: |
657 case QImage::Format_MonoLSB: |
657 case QImage::Format_MonoLSB: |
687 /*! |
687 /*! |
688 Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent |
688 Returns an image format equivalent to a video frame pixel \a format. If there is no equivalent |
689 format QImage::Format_Invalid is returned instead. |
689 format QImage::Format_Invalid is returned instead. |
690 */ |
690 */ |
691 |
691 |
692 QImage::Format QVideoFrame::equivalentImageFormat(PixelFormat format) |
692 QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format) |
693 { |
693 { |
694 switch (format) { |
694 switch (format) { |
695 case Format_Invalid: |
695 case Format_Invalid: |
696 return QImage::Format_Invalid; |
696 return QImage::Format_Invalid; |
697 case Format_ARGB32: |
697 case Format_ARGB32: |