/src/mozilla-central/dom/media/VideoSegment.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | VideoFrame::VideoFrame(already_AddRefed<Image>& aImage, |
18 | | const gfx::IntSize& aIntrinsicSize) |
19 | | : mImage(aImage), mIntrinsicSize(aIntrinsicSize), mForceBlack(false), |
20 | | mPrincipalHandle(PRINCIPAL_HANDLE_NONE) |
21 | 0 | {} |
22 | | |
23 | | VideoFrame::VideoFrame() |
24 | | : mIntrinsicSize(0, 0), mForceBlack(false), mPrincipalHandle(PRINCIPAL_HANDLE_NONE) |
25 | 0 | {} |
26 | | |
27 | | 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 | | VideoFrame::TakeFrom(VideoFrame* aFrame) |
39 | 0 | { |
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 | | VideoFrame::CreateBlackImage(const gfx::IntSize& aSize) |
48 | 0 | { |
49 | 0 | 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 | 0 | } |
55 | 0 | |
56 | 0 | int len = ((aSize.width * aSize.height) * 3 / 2); |
57 | 0 |
|
58 | 0 | // Generate a black image. |
59 | 0 | auto frame = MakeUnique<uint8_t[]>(len); |
60 | 0 | int y = aSize.width * aSize.height; |
61 | 0 | // Fill Y plane. |
62 | 0 | memset(frame.get(), 0x10, y); |
63 | 0 | // Fill Cb/Cr planes. |
64 | 0 | memset(frame.get() + y, 0x80, (len - y)); |
65 | 0 |
|
66 | 0 | const uint8_t lumaBpp = 8; |
67 | 0 | const uint8_t chromaBpp = 4; |
68 | 0 |
|
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 | 0 |
|
82 | 0 | // Copies data, so we can free data. |
83 | 0 | if (!image->CopyData(data)) { |
84 | 0 | return nullptr; |
85 | 0 | } |
86 | 0 | |
87 | 0 | return image.forget(); |
88 | 0 | } |
89 | | |
90 | | void |
91 | | VideoSegment::AppendFrame(already_AddRefed<Image>&& aImage, |
92 | | StreamTime aDuration, |
93 | | const IntSize& aIntrinsicSize, |
94 | | const PrincipalHandle& aPrincipalHandle, |
95 | | bool aForceBlack, |
96 | | TimeStamp aTimeStamp) |
97 | 0 | { |
98 | 0 | VideoChunk* chunk = AppendChunk(aDuration); |
99 | 0 | chunk->mTimeStamp = aTimeStamp; |
100 | 0 | VideoFrame frame(aImage, aIntrinsicSize); |
101 | 0 | frame.SetForceBlack(aForceBlack); |
102 | 0 | frame.SetPrincipalHandle(aPrincipalHandle); |
103 | 0 | chunk->mFrame.TakeFrom(&frame); |
104 | 0 | } |
105 | | |
106 | | VideoSegment::VideoSegment() |
107 | | : MediaSegmentBase<VideoSegment, VideoChunk>(VIDEO) |
108 | 0 | {} |
109 | | |
110 | | VideoSegment::VideoSegment(VideoSegment&& aSegment) |
111 | | : MediaSegmentBase<VideoSegment, VideoChunk>(std::move(aSegment)) |
112 | 0 | {} |
113 | | |
114 | | VideoSegment::~VideoSegment() |
115 | 0 | {} |
116 | | |
117 | | } // namespace mozilla |