Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "VideoSegment.h"
7 :
8 : #include "gfx2DGlue.h"
9 : #include "ImageContainer.h"
10 : #include "Layers.h"
11 : #include "mozilla/UniquePtr.h"
12 :
13 : namespace mozilla {
14 :
15 : using namespace layers;
16 :
17 0 : VideoFrame::VideoFrame(already_AddRefed<Image>& aImage,
18 0 : const gfx::IntSize& aIntrinsicSize)
19 : : mImage(aImage), mIntrinsicSize(aIntrinsicSize), mForceBlack(false),
20 0 : mPrincipalHandle(PRINCIPAL_HANDLE_NONE)
21 0 : {}
22 :
23 0 : VideoFrame::VideoFrame()
24 0 : : mIntrinsicSize(0, 0), mForceBlack(false), mPrincipalHandle(PRINCIPAL_HANDLE_NONE)
25 0 : {}
26 :
27 0 : VideoFrame::~VideoFrame()
28 0 : {}
29 :
30 : void
31 0 : VideoFrame::SetNull() {
32 0 : mImage = nullptr;
33 0 : mIntrinsicSize = gfx::IntSize(0, 0);
34 0 : mPrincipalHandle = PRINCIPAL_HANDLE_NONE;
35 0 : }
36 :
37 : void
38 0 : VideoFrame::TakeFrom(VideoFrame* aFrame)
39 : {
40 0 : mImage = aFrame->mImage.forget();
41 0 : mIntrinsicSize = aFrame->mIntrinsicSize;
42 0 : mForceBlack = aFrame->GetForceBlack();
43 0 : mPrincipalHandle = aFrame->mPrincipalHandle;
44 0 : }
45 :
46 : /* static */ already_AddRefed<Image>
47 0 : VideoFrame::CreateBlackImage(const gfx::IntSize& aSize)
48 : {
49 : RefPtr<ImageContainer> container =
50 0 : LayerManager::CreateImageContainer(ImageContainer::ASYNCHRONOUS);
51 0 : RefPtr<PlanarYCbCrImage> image = container->CreatePlanarYCbCrImage();
52 0 : if (!image) {
53 0 : return nullptr;
54 : }
55 :
56 0 : int len = ((aSize.width * aSize.height) * 3 / 2);
57 :
58 : // Generate a black image.
59 0 : auto frame = MakeUnique<uint8_t[]>(len);
60 0 : int y = aSize.width * aSize.height;
61 : // Fill Y plane.
62 0 : memset(frame.get(), 0x10, y);
63 : // Fill Cb/Cr planes.
64 0 : memset(frame.get() + y, 0x80, (len - y));
65 :
66 0 : const uint8_t lumaBpp = 8;
67 0 : const uint8_t chromaBpp = 4;
68 :
69 0 : layers::PlanarYCbCrData data;
70 0 : data.mYChannel = frame.get();
71 0 : data.mYSize = gfx::IntSize(aSize.width, aSize.height);
72 0 : data.mYStride = (int32_t) (aSize.width * lumaBpp / 8.0);
73 0 : data.mCbCrStride = (int32_t) (aSize.width * chromaBpp / 8.0);
74 0 : data.mCbChannel = frame.get() + aSize.height * data.mYStride;
75 0 : data.mCrChannel = data.mCbChannel + aSize.height * data.mCbCrStride / 2;
76 0 : data.mCbCrSize = gfx::IntSize(aSize.width / 2, aSize.height / 2);
77 0 : data.mPicX = 0;
78 0 : data.mPicY = 0;
79 0 : data.mPicSize = gfx::IntSize(aSize.width, aSize.height);
80 0 : data.mStereoMode = StereoMode::MONO;
81 :
82 : // Copies data, so we can free data.
83 0 : if (!image->CopyData(data)) {
84 0 : return nullptr;
85 : }
86 :
87 0 : return image.forget();
88 : }
89 :
90 0 : VideoChunk::VideoChunk()
91 0 : {}
92 :
93 0 : VideoChunk::~VideoChunk()
94 0 : {}
95 :
96 : void
97 0 : VideoSegment::AppendFrame(already_AddRefed<Image>&& aImage,
98 : StreamTime aDuration,
99 : const IntSize& aIntrinsicSize,
100 : const PrincipalHandle& aPrincipalHandle,
101 : bool aForceBlack,
102 : TimeStamp aTimeStamp)
103 : {
104 0 : VideoChunk* chunk = AppendChunk(aDuration);
105 0 : chunk->mTimeStamp = aTimeStamp;
106 0 : VideoFrame frame(aImage, aIntrinsicSize);
107 0 : frame.SetForceBlack(aForceBlack);
108 0 : frame.SetPrincipalHandle(aPrincipalHandle);
109 0 : chunk->mFrame.TakeFrom(&frame);
110 0 : }
111 :
112 0 : VideoSegment::VideoSegment()
113 0 : : MediaSegmentBase<VideoSegment, VideoChunk>(VIDEO)
114 0 : {}
115 :
116 0 : VideoSegment::~VideoSegment()
117 0 : {}
118 :
119 : } // namespace mozilla
|