1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef AMEDIAOBJECTS_H_
18 #define AMEDIAOBJECTS_H_
19 
20 #include <utils/Log.h>
21 
22 #include "media/NdkMediaCrypto.h"
23 #include "media/NdkMediaDrm.h"
24 #include "media/NdkMediaExtractor.h"
25 
26 namespace {
27 
28 // Simple class to manage deletion of AMedia objects
29 class AMediaObjects {
30  public:
31     AMediaObjects();
32     virtual ~AMediaObjects();
33 
setCrypto(AMediaCrypto * const theCrypto)34     void setCrypto(AMediaCrypto* const theCrypto) {
35         mCrypto = theCrypto;
36     }
setDrm(AMediaDrm * const theDrm)37     void setDrm(AMediaDrm* const theDrm) {
38         mDrm = theDrm;
39     }
setVideoExtractor(AMediaExtractor * const theExtractor)40     void setVideoExtractor(AMediaExtractor* const theExtractor) {
41         mVideoExtractor = theExtractor;
42     }
setAudioExtractor(AMediaExtractor * const theExtractor)43     void setAudioExtractor(AMediaExtractor* const theExtractor) {
44         mAudioExtractor = theExtractor;
45     }
46 
getCrypto()47     AMediaCrypto* getCrypto() const { return mCrypto; }
getDrm()48     AMediaDrm* getDrm() const { return mDrm; }
getAudioExtractor()49     AMediaExtractor* getAudioExtractor() const { return mAudioExtractor; }
getVideoExtractor()50     AMediaExtractor* getVideoExtractor() const { return mVideoExtractor; }
51 
52  private:
53     AMediaCrypto *mCrypto;
54     AMediaDrm* mDrm;
55     AMediaExtractor* mAudioExtractor;
56     AMediaExtractor* mVideoExtractor;
57 
58     // Disallow copy and assignment
59     AMediaObjects(const AMediaObjects&);
60     void operator=(const AMediaObjects&);
61 };
62 
AMediaObjects(void)63 AMediaObjects::AMediaObjects(void) : mCrypto(NULL), mDrm(NULL),
64         mAudioExtractor(NULL), mVideoExtractor(NULL) {
65 }
66 
~AMediaObjects()67 AMediaObjects::~AMediaObjects() {
68     if (mCrypto) {
69         AMediaCrypto_delete(mCrypto);
70     }
71     if (mAudioExtractor) {
72         AMediaExtractor_delete(mAudioExtractor);
73     }
74     if (mVideoExtractor) {
75         AMediaExtractor_delete(mVideoExtractor);
76     }
77     if (mDrm) {
78         AMediaDrm_release(mDrm);
79     }
80 }
81 
82 }  // anonymous namespace
83 #endif  // AMEDIAOBJECTS_H_
84 
85