1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_MEDIA_ROUTER_COMMON_MEDIA_ROUTE_H_
6 #define COMPONENTS_MEDIA_ROUTER_COMMON_MEDIA_ROUTE_H_
7 
8 #include <iosfwd>
9 #include <string>
10 
11 #include "base/values.h"
12 #include "components/media_router/common/media_sink.h"
13 #include "components/media_router/common/media_source.h"
14 
15 namespace media_router {
16 
17 // TODO(imcheng): Use the Mojo enum directly once we Mojo-ified
18 // MediaRouterAndroid.
19 enum class RouteControllerType { kNone, kGeneric, kMirroring };
20 
21 // MediaRoute objects contain the status and metadata of a routing
22 // operation. The fields are immutable and reflect the route status
23 // only at the time of object creation. Updated route statuses must
24 // be retrieved as new MediaRoute objects from the Media Router.
25 //
26 // TODO(mfoltz): Convert to a simple struct and remove uncommon parameters from
27 // the ctor.
28 class MediaRoute {
29  public:
30   using Id = std::string;
31 
32   static MediaRoute::Id GetMediaRouteId(const std::string& presentation_id,
33                                         const MediaSink::Id& sink_id,
34                                         const MediaSource& source);
35   static std::string GetPresentationIdFromMediaRouteId(
36       const MediaRoute::Id route_id);
37   static std::string GetMediaSourceIdFromMediaRouteId(
38       const MediaRoute::Id route_id);
39 
40   // |media_route_id|: ID of the route.
41   // |media_source|: Description of source of the route.
42   // |media_sink|: The sink that is receiving the media.
43   // |description|: Human readable description of the casting activity.
44   // |is_local|: true if the route was created from this browser.
45   //     provider. empty otherwise.
46   // |for_display|: Set to true if this route should be displayed for
47   //     |media_sink_id| in UI.
48   MediaRoute(const MediaRoute::Id& media_route_id,
49              const MediaSource& media_source,
50              const MediaSink::Id& media_sink_id,
51              const std::string& description,
52              bool is_local,
53              bool for_display);
54   MediaRoute(const MediaRoute& other);
55   MediaRoute();
56 
57   ~MediaRoute();
58 
set_media_route_id(const MediaRoute::Id & media_route_id)59   void set_media_route_id(const MediaRoute::Id& media_route_id) {
60     media_route_id_ = media_route_id;
61   }
media_route_id()62   const MediaRoute::Id& media_route_id() const { return media_route_id_; }
63 
set_presentation_id(const std::string & presentation_id)64   void set_presentation_id(const std::string& presentation_id) {
65     presentation_id_ = presentation_id;
66   }
presentation_id()67   const std::string& presentation_id() const { return presentation_id_; }
68 
set_media_source(const MediaSource & media_source)69   void set_media_source(const MediaSource& media_source) {
70     media_source_ = media_source;
71   }
media_source()72   const MediaSource& media_source() const { return media_source_; }
73 
set_media_sink_id(const MediaSink::Id & media_sink_id)74   void set_media_sink_id(const MediaSink::Id& media_sink_id) {
75     media_sink_id_ = media_sink_id;
76   }
media_sink_id()77   const MediaSink::Id& media_sink_id() const { return media_sink_id_; }
78 
set_media_sink_name(const std::string & media_sink_name)79   void set_media_sink_name(const std::string& media_sink_name) {
80     media_sink_name_ = media_sink_name;
81   }
media_sink_name()82   const std::string& media_sink_name() const { return media_sink_name_; }
83 
set_description(const std::string & description)84   void set_description(const std::string& description) {
85     description_ = description;
86   }
87 
88   // TODO(kmarshall): Do we need to pass locale for bidi rendering?
description()89   const std::string& description() const { return description_; }
90 
set_local(bool is_local)91   void set_local(bool is_local) { is_local_ = is_local; }
is_local()92   bool is_local() const { return is_local_; }
93 
set_controller_type(RouteControllerType controller_type)94   void set_controller_type(RouteControllerType controller_type) {
95     controller_type_ = controller_type;
96   }
controller_type()97   RouteControllerType controller_type() const { return controller_type_; }
98 
set_for_display(bool for_display)99   void set_for_display(bool for_display) { for_display_ = for_display; }
for_display()100   bool for_display() const { return for_display_; }
101 
set_off_the_record(bool is_off_the_record)102   void set_off_the_record(bool is_off_the_record) {
103     is_off_the_record_ = is_off_the_record;
104   }
is_off_the_record()105   bool is_off_the_record() const { return is_off_the_record_; }
106 
set_local_presentation(bool is_local_presentation)107   void set_local_presentation(bool is_local_presentation) {
108     is_local_presentation_ = is_local_presentation;
109   }
is_local_presentation()110   bool is_local_presentation() const { return is_local_presentation_; }
111 
112   bool operator==(const MediaRoute& other) const;
113 
114  private:
115   friend std::ostream& operator<<(std::ostream& stream,
116                                   const MediaRoute& route);
117 
118   // The media route identifier.
119   MediaRoute::Id media_route_id_;
120 
121   // The ID of the presentation that this route is associated with.
122   std::string presentation_id_;
123 
124   // The media source being routed.
125   MediaSource media_source_;
126 
127   // The ID of sink being routed to.
128   MediaSink::Id media_sink_id_;
129 
130   // Human readable name of the sink.
131   std::string media_sink_name_;
132 
133   // Human readable description of the casting activity.  Examples:
134   // "Mirroring tab (www.example.com)", "Casting media", "Casting YouTube"
135   std::string description_;
136 
137   // |true| if the route is created locally (versus discovered by a media route
138   // provider.)
139   bool is_local_ = false;
140 
141   // The type of MediaRouteController supported by this route.
142   RouteControllerType controller_type_ = RouteControllerType::kNone;
143 
144   // |true| if the route can be displayed in the UI.
145   bool for_display_ = false;
146 
147   // |true| if the route was created by an OffTheRecord profile.
148   bool is_off_the_record_ = false;
149 
150   // |true| if the presentation associated with this route is a local
151   // presentation.
152   bool is_local_presentation_ = false;
153 };
154 
155 }  // namespace media_router
156 
157 #endif  // COMPONENTS_MEDIA_ROUTER_COMMON_MEDIA_ROUTE_H_
158