ChromiumHTTPDataSource.h revision 9d2f386dd2885eaffa11fd494ae258bb09fe6397
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(const char *mime);
47
48    virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
49
50    virtual String8 getUri();
51
52    virtual String8 getMIMEType() const;
53
54    virtual status_t reconnectAtOffset(off64_t offset);
55
56protected:
57    virtual ~ChromiumHTTPDataSource();
58
59private:
60    friend struct SfDelegate;
61
62    enum State {
63        DISCONNECTED,
64        CONNECTING,
65        CONNECTED,
66        READING,
67        DISCONNECTING
68    };
69
70    const uint32_t mFlags;
71
72    mutable Mutex mLock;
73    Condition mCondition;
74
75    State mState;
76
77    SfDelegate *mDelegate;
78
79    AString mURI;
80    KeyedVector<String8, String8> mHeaders;
81
82    off64_t mCurrentOffset;
83
84    // Any connection error or the result of a read operation
85    // (for the lattter this is the number of bytes read, if successful).
86    ssize_t mIOResult;
87
88    int64_t mContentSize;
89
90    String8 mContentType;
91
92    sp<DecryptHandle> mDecryptHandle;
93    DrmManagerClient *mDrmManagerClient;
94
95    void disconnect_l();
96
97    status_t connect_l(
98            const char *uri,
99            const KeyedVector<String8, String8> *headers,
100            off64_t offset);
101
102    static void InitiateRead(
103            ChromiumHTTPDataSource *me, void *data, size_t size);
104
105    void initiateRead(void *data, size_t size);
106
107    void onConnectionEstablished(
108            int64_t contentSize, const char *contentType);
109
110    void onConnectionFailed(status_t err);
111    void onReadCompleted(ssize_t size);
112    void onDisconnectComplete();
113
114    void clearDRMState_l();
115
116    DISALLOW_EVIL_CONSTRUCTORS(ChromiumHTTPDataSource);
117};
118
119}  // namespace android
120
121#endif  // CHROME_HTTP_DATA_SOURCE_H_
122