ChromiumHTTPDataSource.h revision 5b1b8a93a07326f1cbc627f09e02988375189e0a
1/*
2 * Copyright (C) 2011 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 CHROME_HTTP_DATA_SOURCE_H_
18
19#define CHROME_HTTP_DATA_SOURCE_H_
20
21#include <media/stagefright/foundation/AString.h>
22#include <utils/threads.h>
23
24#include "HTTPBase.h"
25
26namespace android {
27
28struct SfDelegate;
29
30struct ChromiumHTTPDataSource : public HTTPBase {
31    ChromiumHTTPDataSource(uint32_t flags = 0);
32
33    virtual status_t connect(
34            const char *uri,
35            const KeyedVector<String8, String8> *headers = NULL,
36            off64_t offset = 0);
37
38    virtual void disconnect();
39
40    virtual status_t initCheck() const;
41
42    virtual ssize_t readAt(off64_t offset, void *data, size_t size);
43    virtual status_t getSize(off64_t *size);
44    virtual uint32_t flags();
45
46    virtual sp<DecryptHandle> DrmInitialization();
47
48    virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
49
50    virtual String8 getUri();
51
52    virtual String8 getMIMEType() const;
53
54protected:
55    virtual ~ChromiumHTTPDataSource();
56
57private:
58    friend struct SfDelegate;
59
60    enum State {
61        DISCONNECTED,
62        CONNECTING,
63        CONNECTED,
64        READING,
65        DISCONNECTING
66    };
67
68    const uint32_t mFlags;
69
70    mutable Mutex mLock;
71    Condition mCondition;
72
73    State mState;
74
75    SfDelegate *mDelegate;
76
77    AString mURI;
78    KeyedVector<String8, String8> mHeaders;
79
80    off64_t mCurrentOffset;
81
82    // Any connection error or the result of a read operation
83    // (for the lattter this is the number of bytes read, if successful).
84    ssize_t mIOResult;
85
86    int64_t mContentSize;
87
88    String8 mContentType;
89
90    sp<DecryptHandle> mDecryptHandle;
91    DrmManagerClient *mDrmManagerClient;
92
93    void disconnect_l();
94
95    status_t connect_l(
96            const char *uri,
97            const KeyedVector<String8, String8> *headers,
98            off64_t offset);
99
100    static void InitiateRead(
101            ChromiumHTTPDataSource *me, void *data, size_t size);
102
103    void initiateRead(void *data, size_t size);
104
105    void onConnectionEstablished(
106            int64_t contentSize, const char *contentType);
107
108    void onConnectionFailed(status_t err);
109    void onReadCompleted(ssize_t size);
110    void onDisconnectComplete();
111
112    void clearDRMState_l();
113
114    DISALLOW_EVIL_CONSTRUCTORS(ChromiumHTTPDataSource);
115};
116
117}  // namespace android
118
119#endif  // CHROME_HTTP_DATA_SOURCE_H_
120