content/media/encoder/fmp4_muxer/AVCBox.cpp

branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
equal deleted inserted replaced
-1:000000000000 0:15855f4d3b9c
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 <climits>
7 #include "ISOControl.h"
8 #include "ISOMediaBoxes.h"
9 #include "AVCBox.h"
10
11 namespace mozilla {
12
13 nsresult
14 AVCSampleEntry::Generate(uint32_t* aBoxSize)
15 {
16 uint32_t avc_box_size = 0;
17 nsresult rv;
18 rv = avcConfigBox->Generate(&avc_box_size);
19 NS_ENSURE_SUCCESS(rv, rv);
20
21 size += avc_box_size;
22
23 *aBoxSize = size;
24
25 return NS_OK;
26 }
27
28 nsresult
29 AVCSampleEntry::Write()
30 {
31 BoxSizeChecker checker(mControl, size);
32 nsresult rv;
33 rv = VisualSampleEntry::Write();
34 NS_ENSURE_SUCCESS(rv, rv);
35 rv = avcConfigBox->Write();
36 NS_ENSURE_SUCCESS(rv, rv);
37
38 return NS_OK;
39 }
40
41 AVCSampleEntry::AVCSampleEntry(ISOControl* aControl)
42 : VisualSampleEntry(NS_LITERAL_CSTRING("avc1"), aControl)
43 {
44 avcConfigBox = new AVCConfigurationBox(aControl);
45 MOZ_COUNT_CTOR(AVCSampleEntry);
46 }
47
48 AVCSampleEntry::~AVCSampleEntry()
49 {
50 MOZ_COUNT_DTOR(AVCSampleEntry);
51 }
52
53 AVCConfigurationBox::AVCConfigurationBox(ISOControl* aControl)
54 : Box(NS_LITERAL_CSTRING("avcC"), aControl)
55 {
56 MOZ_COUNT_CTOR(AVCConfigurationBox);
57 }
58
59 AVCConfigurationBox::~AVCConfigurationBox()
60 {
61 MOZ_COUNT_DTOR(AVCConfigurationBox);
62 }
63
64 nsresult
65 AVCConfigurationBox::Generate(uint32_t* aBoxSize)
66 {
67 nsresult rv;
68 FragmentBuffer* frag = mControl->GetFragment(Video_Track);
69 rv = frag->GetCSD(avcConfig);
70 NS_ENSURE_SUCCESS(rv, rv);
71 size += avcConfig.Length();
72 *aBoxSize = size;
73 return NS_OK;
74 }
75
76 nsresult
77 AVCConfigurationBox::Write()
78 {
79 BoxSizeChecker checker(mControl, size);
80 Box::Write();
81
82 mControl->Write(avcConfig.Elements(), avcConfig.Length());
83
84 return NS_OK;
85 }
86
87 }

mercurial