aboutsummaryrefslogtreecommitdiff
path: root/packet/avrcp
diff options
context:
space:
mode:
authorAjay Panicker <apanicke@google.com>2018-02-21 21:04:24 -0800
committerAjay Panicker <apanicke@google.com>2018-02-28 20:28:55 -0800
commit2c822c94aa90b1014800633fe6f663d5598be196 (patch)
tree1168d8123f3ae80d3731a2f936963d132a62a68e /packet/avrcp
parent51a906ba83f8f7cb2a455862df74fb2e63eafc7b (diff)
downloadbt-2c822c94aa90b1014800633fe6f663d5598be196.tar.gz
Add the AVRCP Device class for the AVRCP Refactor
The AVRCP Device class handles all the state tracking for each connected device as well as handling all the different message responses. Bug: 68854188 Test: run_host_unit_tests.py && run_unit_tests.sh net_test_avrcp Change-Id: Ic39337eff3e404ca3c2d96f48e79948fac83d7cb
Diffstat (limited to 'packet/avrcp')
-rw-r--r--packet/avrcp/Android.bp2
-rw-r--r--packet/avrcp/avrcp_common.h287
-rw-r--r--packet/avrcp/avrcp_logging_helper.h239
3 files changed, 2 insertions, 526 deletions
diff --git a/packet/avrcp/Android.bp b/packet/avrcp/Android.bp
index 99c1bad4d..60271f011 100644
--- a/packet/avrcp/Android.bp
+++ b/packet/avrcp/Android.bp
@@ -1,6 +1,8 @@
cc_library_static {
name: "lib-bt-packets-avrcp",
defaults: ["libchrome_support_defaults"],
+ header_libs: ["avrcp_headers"],
+ export_header_lib_headers: ["avrcp_headers"],
export_include_dirs: ["."],
host_supported: true,
srcs: [
diff --git a/packet/avrcp/avrcp_common.h b/packet/avrcp/avrcp_common.h
deleted file mode 100644
index c627ebd94..000000000
--- a/packet/avrcp/avrcp_common.h
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <base/sys_byteorder.h>
-
-#include <map>
-
-// This file contains the different AVRCP Constants
-namespace bluetooth {
-namespace avrcp {
-
-constexpr uint32_t BLUETOOTH_COMPANY_ID = 0x001958;
-
-enum class CType : uint8_t {
- CONTROL = 0x0,
- STATUS = 0x1,
- NOTIFY = 0x3,
- ACCEPTED = 0x9,
- REJECTED = 0xa,
- STABLE = 0xc,
- CHANGED = 0xd,
- INTERIM = 0xf,
-};
-
-enum class Opcode : uint8_t {
- VENDOR = 0x00,
- UNIT_INFO = 0x30,
- SUBUNIT_INFO = 0x31,
- PASS_THROUGH = 0x7c,
-};
-
-// Found in AVRCP_v1.6.1 Section 4.5 Table 4.5
-// Searching can be done in the spec by Camel Casing the constant name
-enum class CommandPdu : uint8_t {
- GET_CAPABILITIES = 0x10,
- LIST_APPLICATION_SETTING_ATTRIBUTES = 0x11,
- GET_ELEMENT_ATTRIBUTES = 0x20,
- GET_PLAY_STATUS = 0x30,
- REGISTER_NOTIFICATION = 0x31,
- SET_ABSOLUTE_VOLUME = 0x50,
- SET_ADDRESSED_PLAYER = 0x60,
- PLAY_ITEM = 0x74,
-};
-
-enum class PacketType : uint8_t {
- SINGLE = 0x00,
-};
-
-enum class Capability : uint8_t {
- COMPANY_ID = 0x02,
- EVENTS_SUPPORTED = 0x03,
-};
-
-// Found in AVRCP_v1.6.1 Section 28 Appendix H
-enum class Event : uint8_t {
- PLAYBACK_STATUS_CHANGED = 0x01,
- TRACK_CHANGED = 0x02,
- PLAYBACK_POS_CHANGED = 0x05,
- PLAYER_APPLICATION_SETTING_CHANGED = 0x08,
- NOW_PLAYING_CONTENT_CHANGED = 0x09,
- AVAILABLE_PLAYERS_CHANGED = 0x0a,
- ADDRESSED_PLAYER_CHANGED = 0x0b,
- UIDS_CHANGED = 0x0c,
- VOLUME_CHANGED = 0x0d,
-};
-
-enum class Attribute : uint32_t {
- TITLE = 0x01,
- ARTIST_NAME = 0x02,
- ALBUM_NAME = 0x03,
- TRACK_NUMBER = 0x04,
- TOTAL_NUMBER_OF_TRACKS = 0x05,
- GENRE = 0x06,
- PLAYING_TIME = 0x07,
- DEFAULT_COVER_ART = 0x08,
-};
-
-enum class Status : uint8_t {
- INVALID_COMMAND = 0x00,
- INVALID_PARAMETER = 0x01,
- PARAMETER_CONTENT_ERROR = 0x02,
- INTERNAL_ERROR = 0x03,
- NO_ERROR = 0x04,
- UIDS_CHANGED = 0x05,
- RESERVED = 0x06,
- INVALID_DIRECTION = 0x07,
- NOT_A_DIRECTORY = 0x08,
- DOES_NOT_EXIST = 0x09,
- INVALID_SCOPE = 0x0a,
- RANGE_OUT_OF_BOUNDS = 0xb,
- FOLDER_ITEM_NOT_PLAYABLE = 0x0c,
- MEDIA_IN_USE = 0x0d,
- NOW_PLAYING_LIST_FULL = 0x0e,
- SEARCH_NOT_SUPPORTED = 0x0f,
- SEARCH_IN_PROGRESS = 0x10,
- INVALID_PLAYER_ID = 0x11,
- PLAYER_NOT_BROWSABLE = 0x12,
- PLAYER_NOT_ADDRESSED = 0x13,
- NO_VALID_SEARCH_RESULTS = 0x14,
- NO_AVAILABLE_PLAYERS = 0x15,
- ADDRESSED_PLAYER_CHANGED = 0x16,
-};
-
-enum class BrowsePdu : uint8_t {
- SET_BROWSED_PLAYER = 0x70,
- GET_FOLDER_ITEMS = 0x71,
- CHANGE_PATH = 0x72,
- GET_ITEM_ATTRIBUTES = 0x73,
- GET_TOTAL_NUMBER_OF_ITEMS = 0x75,
-};
-
-enum class Scope : uint8_t {
- MEDIA_PLAYER_LIST = 0x00,
- VFS = 0x01,
- SEARCH = 0x02,
- NOW_PLAYING = 0x03,
-};
-
-enum class Direction : uint8_t {
- UP = 0x00,
- DOWN = 0x01,
-};
-
-using AttributeEntry = std::pair<Attribute, std::string>;
-
-struct MediaPlayerItem {
- uint16_t id_;
- std::string name_;
- bool browsable_;
-
- MediaPlayerItem(uint16_t id, std::string name, bool browsable)
- : id_(id), name_(name), browsable_(browsable) {}
-
- MediaPlayerItem(const MediaPlayerItem&) = default;
-
- static size_t size(const MediaPlayerItem& item) {
- size_t ret = 0;
- ret += 1; // Media Player Type
- ret += 2; // Item Length
- ret += 2; // Player Id
- ret += 1; // Player Type
- ret += 4; // Player Subtype
- ret += 1; // Play Status
- ret += 16; // Features
- ret += 2; // UTF-8 character set
- ret += 2; // Name Length
- ret += item.name_.size();
- return ret;
- }
-};
-
-struct FolderItem {
- uint64_t uid_;
- uint8_t folder_type_;
- bool is_playable_;
- std::string name_;
-
- FolderItem(uint64_t uid, uint8_t folder_type, bool is_playable,
- const std::string& name)
- : uid_(uid),
- folder_type_(folder_type),
- is_playable_(is_playable),
- name_(name) {}
-
- FolderItem(const FolderItem&) = default;
-
- static size_t size(const FolderItem& item) {
- size_t ret = 0;
- ret += 1; // Folder Item Type
- ret += 2; // Item Length
- ret += 8; // Folder UID
- ret += 1; // Folder Type
- ret += 1; // Is Playable byte
- ret += 2; // UTF-8 Character Set
- ret += 2; // Name Length
- ret += item.name_.size();
- return ret;
- }
-};
-
-// NOTE: We never use media type field because we only support audio types
-struct MediaElementItem {
- uint64_t uid_ = 0;
- std::string name_;
- std::map<Attribute, std::string> attributes_;
-
- MediaElementItem(uint64_t uid, std::string name,
- std::map<Attribute, std::string> attributes)
- : uid_(uid), name_(name), attributes_(attributes) {}
-
- MediaElementItem(const MediaElementItem&) = default;
-
- static size_t size(const MediaElementItem& item) {
- size_t ret = 0;
- ret += 1; // Media Element Item Type
- ret += 2; // Item Length
- ret += 8; // Item UID
- ret += 1; // Media Type
- ret += 2; // UTF-8 Character Set
- ret += 2; // Name Length
- ret += item.name_.size();
- ret += 1; // Number of Attributes
- for (auto it = item.attributes_.begin(); it != item.attributes_.end();
- it++) {
- ret += 4; // Attribute ID
- ret += 2; // UTF-8 Character Set
- ret += 2; // Attribute Length
- ret += it->second.size();
- }
-
- return ret;
- }
-};
-
-struct MediaListItem {
- enum : uint8_t { PLAYER = 0x01, FOLDER = 0x02, SONG = 0x03 } type_;
-
- union {
- MediaPlayerItem player_;
- FolderItem folder_;
- MediaElementItem song_;
- };
-
- MediaListItem(MediaPlayerItem item) : type_(PLAYER), player_(item) {}
-
- MediaListItem(FolderItem item) : type_(FOLDER), folder_(item) {}
-
- MediaListItem(MediaElementItem item) : type_(SONG), song_(item) {}
-
- MediaListItem(const MediaListItem& item) {
- type_ = item.type_;
- switch (item.type_) {
- case PLAYER:
- new (&player_) MediaPlayerItem(item.player_);
- return;
- case FOLDER:
- new (&folder_) FolderItem(item.folder_);
- return;
- case SONG:
- new (&song_) MediaElementItem(item.song_);
- return;
- }
- }
-
- ~MediaListItem() {
- switch (type_) {
- case PLAYER:
- player_.~MediaPlayerItem();
- return;
- case FOLDER:
- folder_.~FolderItem();
- return;
- case SONG:
- song_.~MediaElementItem();
- return;
- }
- }
-
- static size_t size(const MediaListItem& item) {
- switch (item.type_) {
- case PLAYER:
- return MediaPlayerItem::size(item.player_);
- case FOLDER:
- return FolderItem::size(item.folder_);
- case SONG:
- return MediaElementItem::size(item.song_);
- }
- }
-};
-
-} // namespace avrcp
-} // namespace bluetooth \ No newline at end of file
diff --git a/packet/avrcp/avrcp_logging_helper.h b/packet/avrcp/avrcp_logging_helper.h
deleted file mode 100644
index f2f0b3258..000000000
--- a/packet/avrcp/avrcp_logging_helper.h
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include <type_traits>
-
-#include "avrcp_common.h"
-
-// We have our own definition of loghex to avoid dependencies
-namespace {
-template <typename T>
-std::string loghex(T x) {
- std::stringstream tmp;
- tmp << "0x" << std::internal << std::hex << std::setfill('0')
- << std::setw(sizeof(T) * 2) << (unsigned int)x;
- return tmp.str();
-}
-} // namespace
-
-namespace bluetooth {
-namespace avrcp {
-
-#define CASE_RETURN_TEXT(code) \
- case code: \
- return #code
-
-inline std::string CTypeText(const CType& type) {
- switch (type) {
- CASE_RETURN_TEXT(CType::CONTROL);
- CASE_RETURN_TEXT(CType::STATUS);
- CASE_RETURN_TEXT(CType::NOTIFY);
- CASE_RETURN_TEXT(CType::ACCEPTED);
- CASE_RETURN_TEXT(CType::REJECTED);
- CASE_RETURN_TEXT(CType::STABLE);
- CASE_RETURN_TEXT(CType::CHANGED);
- CASE_RETURN_TEXT(CType::INTERIM);
- default:
- return "Unknown CType: " + loghex(type);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const CType& type) {
- return os << CTypeText(type);
-}
-
-inline std::string OpcodeText(const Opcode& opcode) {
- switch (opcode) {
- CASE_RETURN_TEXT(Opcode::VENDOR);
- CASE_RETURN_TEXT(Opcode::UNIT_INFO);
- CASE_RETURN_TEXT(Opcode::SUBUNIT_INFO);
- CASE_RETURN_TEXT(Opcode::PASS_THROUGH);
- default:
- return "Unknown Opcode: " + loghex(opcode);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const Opcode& opcode) {
- return os << OpcodeText(opcode);
-}
-
-inline std::string CommandPduText(const CommandPdu& pdu) {
- switch (pdu) {
- CASE_RETURN_TEXT(CommandPdu::GET_CAPABILITIES);
- CASE_RETURN_TEXT(CommandPdu::LIST_APPLICATION_SETTING_ATTRIBUTES);
- CASE_RETURN_TEXT(CommandPdu::GET_ELEMENT_ATTRIBUTES);
- CASE_RETURN_TEXT(CommandPdu::GET_PLAY_STATUS);
- CASE_RETURN_TEXT(CommandPdu::REGISTER_NOTIFICATION);
- CASE_RETURN_TEXT(CommandPdu::SET_ADDRESSED_PLAYER);
- CASE_RETURN_TEXT(CommandPdu::PLAY_ITEM);
- default:
- return "Unknown Command PDU: " + loghex(pdu);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const CommandPdu& pdu) {
- return os << CommandPduText(pdu);
-}
-
-inline std::string PacketTypeText(const PacketType& type) {
- switch (type) {
- CASE_RETURN_TEXT(PacketType::SINGLE);
- default:
- return "Unknown Packet Type: " + loghex(type);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const PacketType& type) {
- return os << PacketTypeText(type);
-}
-
-inline std::string CapabilityText(const Capability& cap) {
- switch (cap) {
- CASE_RETURN_TEXT(Capability::COMPANY_ID);
- CASE_RETURN_TEXT(Capability::EVENTS_SUPPORTED);
- default:
- return "Unknown Capability: " + loghex(cap);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const Capability& cap) {
- return os << CapabilityText(cap);
-}
-
-inline std::string EventText(const Event& event) {
- switch (event) {
- CASE_RETURN_TEXT(Event::PLAYBACK_STATUS_CHANGED);
- CASE_RETURN_TEXT(Event::TRACK_CHANGED);
- CASE_RETURN_TEXT(Event::PLAYBACK_POS_CHANGED);
- CASE_RETURN_TEXT(Event::PLAYER_APPLICATION_SETTING_CHANGED);
- CASE_RETURN_TEXT(Event::NOW_PLAYING_CONTENT_CHANGED);
- CASE_RETURN_TEXT(Event::AVAILABLE_PLAYERS_CHANGED);
- CASE_RETURN_TEXT(Event::ADDRESSED_PLAYER_CHANGED);
- CASE_RETURN_TEXT(Event::UIDS_CHANGED);
- CASE_RETURN_TEXT(Event::VOLUME_CHANGED);
- default:
- return "Unknown Event: " + loghex(event);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const Event& event) {
- return os << EventText(event);
-}
-
-inline std::string AttributeText(const Attribute& attr) {
- switch (attr) {
- CASE_RETURN_TEXT(Attribute::TITLE);
- CASE_RETURN_TEXT(Attribute::ARTIST_NAME);
- CASE_RETURN_TEXT(Attribute::ALBUM_NAME);
- CASE_RETURN_TEXT(Attribute::TRACK_NUMBER);
- CASE_RETURN_TEXT(Attribute::TOTAL_NUMBER_OF_TRACKS);
- CASE_RETURN_TEXT(Attribute::GENRE);
- CASE_RETURN_TEXT(Attribute::PLAYING_TIME);
- CASE_RETURN_TEXT(Attribute::DEFAULT_COVER_ART);
- default:
- return "Unknown Attribute Value: " + loghex(attr);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const Attribute& attr) {
- return os << AttributeText(attr);
-}
-
-inline std::string StatusText(const Status& status) {
- switch (status) {
- CASE_RETURN_TEXT(Status::INVALID_COMMAND);
- CASE_RETURN_TEXT(Status::INVALID_PARAMETER);
- CASE_RETURN_TEXT(Status::PARAMETER_CONTENT_ERROR);
- CASE_RETURN_TEXT(Status::INTERNAL_ERROR);
- CASE_RETURN_TEXT(Status::NO_ERROR);
- CASE_RETURN_TEXT(Status::UIDS_CHANGED);
- CASE_RETURN_TEXT(Status::RESERVED);
- CASE_RETURN_TEXT(Status::INVALID_DIRECTION);
- CASE_RETURN_TEXT(Status::NOT_A_DIRECTORY);
- CASE_RETURN_TEXT(Status::DOES_NOT_EXIST);
- CASE_RETURN_TEXT(Status::INVALID_SCOPE);
- CASE_RETURN_TEXT(Status::RANGE_OUT_OF_BOUNDS);
- CASE_RETURN_TEXT(Status::FOLDER_ITEM_NOT_PLAYABLE);
- CASE_RETURN_TEXT(Status::MEDIA_IN_USE);
- CASE_RETURN_TEXT(Status::NOW_PLAYING_LIST_FULL);
- CASE_RETURN_TEXT(Status::SEARCH_NOT_SUPPORTED);
- CASE_RETURN_TEXT(Status::SEARCH_IN_PROGRESS);
- CASE_RETURN_TEXT(Status::INVALID_PLAYER_ID);
- CASE_RETURN_TEXT(Status::PLAYER_NOT_BROWSABLE);
- CASE_RETURN_TEXT(Status::PLAYER_NOT_ADDRESSED);
- CASE_RETURN_TEXT(Status::NO_VALID_SEARCH_RESULTS);
- CASE_RETURN_TEXT(Status::NO_AVAILABLE_PLAYERS);
- CASE_RETURN_TEXT(Status::ADDRESSED_PLAYER_CHANGED);
- default:
- return "Unknown Status: " + loghex(status);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const Status& status) {
- return os << StatusText(status);
-}
-
-inline std::string BrowsePduText(const BrowsePdu& pdu) {
- switch (pdu) {
- CASE_RETURN_TEXT(BrowsePdu::SET_BROWSED_PLAYER);
- CASE_RETURN_TEXT(BrowsePdu::GET_FOLDER_ITEMS);
- CASE_RETURN_TEXT(BrowsePdu::CHANGE_PATH);
- CASE_RETURN_TEXT(BrowsePdu::GET_ITEM_ATTRIBUTES);
- default:
- return "Unknown Browse Pdu: " + loghex(pdu);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const BrowsePdu& pdu) {
- return os << BrowsePduText(pdu);
-}
-
-inline std::string ScopeText(const Scope& scope) {
- switch (scope) {
- CASE_RETURN_TEXT(Scope::MEDIA_PLAYER_LIST);
- CASE_RETURN_TEXT(Scope::VFS);
- CASE_RETURN_TEXT(Scope::SEARCH);
- CASE_RETURN_TEXT(Scope::NOW_PLAYING);
- default:
- return "Unknown Scope: " + loghex(scope);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const Scope& pdu) {
- return os << ScopeText(pdu);
-}
-
-inline std::string DirectionText(const Direction& dir) {
- switch (dir) {
- CASE_RETURN_TEXT(Direction::UP);
- CASE_RETURN_TEXT(Direction::DOWN);
- default:
- return "Unknown Direction: " + loghex(dir);
- }
-}
-
-inline std::ostream& operator<<(std::ostream& os, const Direction& dir) {
- return os << DirectionText(dir);
-}
-
-} // namespace avrcp
-} // namespace bluetooth \ No newline at end of file