• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #pragma once
15 
16 #include "host-common/AddressSpaceService.h"
17 #include "host-common/address_space_device.h"
18 #include "host-common/GoldfishMediaDefs.h"
19 #include "host-common/MediaVpxDecoder.h"
20 #include "host-common/MediaH264Decoder.h"
21 
22 #include <unordered_map>
23 
24 namespace android {
25 namespace emulation {
26 
27 class AddressSpaceHostMediaContext : public AddressSpaceDeviceContext {
28 public:
29     AddressSpaceHostMediaContext(uint64_t phys_addr, const address_space_device_control_ops* ops, bool fromSnapshot);
30     virtual ~AddressSpaceHostMediaContext();
31     void perform(AddressSpaceDevicePingInfo *info) override;
32 
33     AddressSpaceDeviceType getDeviceType() const override;
34     void save(base::Stream* stream) const override;
35     bool load(base::Stream* stream) override;
36 
37 private:
38     void allocatePages(uint64_t phys_addr, int num_pages);
39     void deallocatePages(uint64_t phys_addr, int num_pages);
40     void handleMediaRequest(AddressSpaceDevicePingInfo *info);
41     static MediaCodecType getMediaCodecType(uint64_t metadata);
42     static MediaOperation getMediaOperation(uint64_t metadata);
43 
44     static constexpr int kAlignment = 4096;
45     static constexpr int kNumPages = 1 + 4096 * 2; // 32M + 4k
46     std::unique_ptr<MediaVpxDecoder> mVpxDecoder;
47     std::unique_ptr<MediaH264Decoder> mH264Decoder;
48     void* mHostBuffer = nullptr;
49     const address_space_device_control_ops* mControlOps = 0;
50     uint64_t mGuestAddr = 0;
51 };
52 
53 }  // namespace emulation
54 }  // namespace android
55