blob: 6ba7c0e281d618187d75995cc871eab3ee85383c [file] [log] [blame]
Andreas Huber20111aa2009-07-14 16:56:47 -07001/*
2 * Copyright (C) 2009 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//#define LOG_NDEBUG 0
18#define LOG_TAG "MediaExtractor"
19#include <utils/Log.h>
Marco Nelissenb2487f02015-09-01 13:23:23 -070020#include <pwd.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070021
Ray Essickdb122142017-01-25 17:51:55 -080022#include <media/MediaAnalyticsItem.h>
Dongwon Kangd91dc5a2017-10-10 00:07:09 -070023#include <media/MediaExtractor.h>
Marco Nelissenb2487f02015-09-01 13:23:23 -070024#include <media/stagefright/foundation/ADebug.h>
Andreas Huberfc9ba092010-01-11 15:35:19 -080025#include <media/stagefright/MetaData.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070026
27namespace android {
28
Ray Essickdb122142017-01-25 17:51:55 -080029// key for media statistics
Ray Essickba13b7b2017-02-07 10:03:18 -080030static const char *kKeyExtractor = "extractor";
Ray Essickdb122142017-01-25 17:51:55 -080031
Marco Nelissen4453f452017-01-13 12:51:08 -080032MediaExtractor::MediaExtractor() {
Marco Nelissenb2487f02015-09-01 13:23:23 -070033 if (!LOG_NDEBUG) {
34 uid_t uid = getuid();
35 struct passwd *pw = getpwuid(uid);
Marco Nelissen75226172016-11-16 14:10:52 -080036 ALOGV("extractor created in uid: %d (%s)", getuid(), pw->pw_name);
Marco Nelissenb2487f02015-09-01 13:23:23 -070037 }
38
Ray Essickdb122142017-01-25 17:51:55 -080039 mAnalyticsItem = NULL;
40 if (MEDIA_LOG) {
Ray Essickba13b7b2017-02-07 10:03:18 -080041 mAnalyticsItem = new MediaAnalyticsItem(kKeyExtractor);
Ray Essickdb122142017-01-25 17:51:55 -080042 (void) mAnalyticsItem->generateSessionID();
43 }
Marco Nelissenb2487f02015-09-01 13:23:23 -070044}
45
Ray Essickdb122142017-01-25 17:51:55 -080046MediaExtractor::~MediaExtractor() {
47
48 // log the current record, provided it has some information worth recording
49 if (MEDIA_LOG) {
50 if (mAnalyticsItem != NULL) {
51 if (mAnalyticsItem->count() > 0) {
52 mAnalyticsItem->setFinalized(true);
53 mAnalyticsItem->selfrecord();
54 }
55 }
56 }
57 if (mAnalyticsItem != NULL) {
58 delete mAnalyticsItem;
59 mAnalyticsItem = NULL;
60 }
61}
Marco Nelissenb2487f02015-09-01 13:23:23 -070062
Andreas Huberfc9ba092010-01-11 15:35:19 -080063sp<MetaData> MediaExtractor::getMetaData() {
64 return new MetaData;
65}
66
Ray Essickba13b7b2017-02-07 10:03:18 -080067status_t MediaExtractor::getMetrics(Parcel *reply) {
68
69 if (mAnalyticsItem == NULL || reply == NULL) {
70 return UNKNOWN_ERROR;
71 }
72
73 populateMetrics();
74 mAnalyticsItem->writeToParcel(reply);
75
76 return OK;
77}
78
79void MediaExtractor::populateMetrics() {
80 ALOGV("MediaExtractor::populateMetrics");
81 // normally overridden in subclasses
82}
83
Andreas Huberacdd9d02010-05-06 10:18:05 -070084uint32_t MediaExtractor::flags() const {
Andreas Huber70f521d2010-10-08 10:16:24 -070085 return CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_PAUSE | CAN_SEEK;
Andreas Huberacdd9d02010-05-06 10:18:05 -070086}
87
Andreas Huber20111aa2009-07-14 16:56:47 -070088} // namespace android