Mir

Merge lp:~kdub/mir/rm-depository-from-screencast into lp:mir

Proposed by Kevin DuBois
Status: Work in progress
Proposed branch: lp:~kdub/mir/rm-depository-from-screencast
Merge into: lp:mir
Diff against target: 162 lines (+72/-11)
3 files modified
src/client/screencast_stream.cpp (+12/-9)
src/client/screencast_stream.h (+3/-2)
tests/unit-tests/client/test_screencast_stream.cpp (+57/-0)
To merge this branch: bzr merge lp:~kdub/mir/rm-depository-from-screencast
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Needs Fixing
Chris Halse Rogers Approve
Mir CI Bot continuous-integration Needs Fixing
Review via email: mp+298298@code.launchpad.net

Commit message

client: remove usage of BufferVault in the ScreencastStream. Disentangles ScreencastStream, preparing for BufferVault's removal once we're ready to remove that code.

This also reduces the client-side number of mapped buffers to just the current one, whereas before, we were keeping 3 around, and kicking out the oldest one as new ones arrived.

Also add a bonus test where I noticed that a wait handle could have been left hanging if an exception threw around buffer creation.

Description of the change

client: remove usage of BufferVault in the ScreencastStream. Disentangles ScreencastStream, preparing for BufferVault's removal once we're ready to remove that code.

This also reduces the client-side number of mapped buffers to just the current one, whereas before, we were keeping 3 around, and kicking out the oldest one as new ones arrived.

Also add a bonus test where I noticed that a wait handle could have been left hanging if an exception threw around buffer creation.

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

Seems sensible.

review: Approve
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

On the server side we are still tracking screencast buffers and support sending mg::BufferIpcMsgType::update_msg buffer messages. The new code (i.e. without BufferDepository) doesn't seem to support this scenario.

review: Needs Fixing
Revision history for this message
Kevin DuBois (kdub) wrote :

recent changes to screencasting have us rotating through the buffers, instead of allocing a new one every time. This did work on the devices I tested with, but we might have to keep BufferVault around after all. Will take MP down to investigate

Unmerged revisions

3534. By Kevin DuBois

merge in mir

3533. By Kevin DuBois

merge in mir

3532. By Kevin DuBois

test to avoid hanging to pass

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/client/screencast_stream.cpp'
2--- src/client/screencast_stream.cpp 2016-06-02 05:33:50 +0000
3+++ src/client/screencast_stream.cpp 2016-06-24 12:39:34 +0000
4@@ -55,8 +55,7 @@
5 client_platform(client_platform),
6 factory(client_platform->create_buffer_factory()),
7 protobuf_bs{mcl::make_protobuf_object<mir::protobuf::BufferStream>(a_protobuf_bs)},
8- protobuf_void{mcl::make_protobuf_object<mir::protobuf::Void>()},
9- buffer_depository{factory}
10+ protobuf_void{mcl::make_protobuf_object<mir::protobuf::Void>()}
11 {
12 if (!protobuf_bs->has_id())
13 {
14@@ -93,9 +92,12 @@
15 try
16 {
17 auto const pixel_format = static_cast<MirPixelFormat>(protobuf_bs->pixel_format());
18- buffer_depository.deposit_package(mcl::protobuf_to_native_buffer(buffer),
19- buffer.buffer_id(), buffer_size,
20- pixel_format);
21+ if (current_buffer_id != buffer.buffer_id())
22+ {
23+ current_buffer = factory->create_buffer(
24+ mcl::protobuf_to_native_buffer(buffer), buffer_size, pixel_format);
25+ current_buffer_id = buffer.buffer_id();
26+ }
27 }
28 catch (const std::runtime_error& error)
29 {
30@@ -104,6 +106,8 @@
31 protobuf_bs->set_error(
32 std::string{"Error processing buffer stream creating response:"} +
33 boost::diagnostic_information(error));
34+ if (screencast_wait_handle.is_pending())
35+ screencast_wait_handle.result_received();
36 throw error;
37 }
38 }
39@@ -132,7 +136,7 @@
40 std::shared_ptr<mcl::ClientBuffer> mcl::ScreencastStream::get_current_buffer()
41 {
42 std::lock_guard<decltype(mutex)> lock(mutex);
43- return buffer_depository.current_buffer();
44+ return current_buffer;
45 }
46
47 EGLNativeWindowType mcl::ScreencastStream::egl_native_window()
48@@ -143,9 +147,8 @@
49 std::shared_ptr<mcl::MemoryRegion> mcl::ScreencastStream::secure_for_cpu_write()
50 {
51 std::lock_guard<decltype(mutex)> lock(mutex);
52- auto buffer = buffer_depository.current_buffer();
53 if (!secured_region)
54- secured_region = buffer->secure_for_cpu_write();
55+ secured_region = current_buffer->secure_for_cpu_write();
56 return secured_region;
57 }
58
59@@ -179,7 +182,7 @@
60 uint32_t mcl::ScreencastStream::get_current_buffer_id()
61 {
62 std::lock_guard<decltype(mutex)> lock(mutex);
63- return buffer_depository.current_buffer_id();
64+ return current_buffer_id;
65 }
66
67 int mcl::ScreencastStream::swap_interval() const
68
69=== modified file 'src/client/screencast_stream.h'
70--- src/client/screencast_stream.h 2016-05-03 06:55:25 +0000
71+++ src/client/screencast_stream.h 2016-06-24 12:39:34 +0000
72@@ -24,7 +24,6 @@
73 #include "mir/egl_native_surface.h"
74 #include "mir/client_buffer.h"
75 #include "client_buffer_stream.h"
76-#include "client_buffer_depository.h"
77 #include "mir/geometry/size.h"
78
79 #include "mir_toolkit/client_types.h"
80@@ -126,7 +125,9 @@
81
82 geometry::Size buffer_size;
83 std::string error_message;
84- ClientBufferDepository buffer_depository;
85+
86+ std::shared_ptr<ClientBuffer> current_buffer;
87+ int32_t current_buffer_id;
88 };
89
90 }
91
92=== modified file 'tests/unit-tests/client/test_screencast_stream.cpp'
93--- tests/unit-tests/client/test_screencast_stream.cpp 2016-01-28 19:05:20 +0000
94+++ tests/unit-tests/client/test_screencast_stream.cpp 2016-06-24 12:39:34 +0000
95@@ -27,6 +27,7 @@
96 #include "mir/test/fake_shared.h"
97 #include "mir_toolkit/mir_client_library.h"
98
99+#include <exception>
100 #include <atomic>
101
102 namespace mp = mir::protobuf;
103@@ -153,3 +154,59 @@
104
105 EXPECT_THAT(stream.get_current_buffer_id(), Eq(id1));
106 }
107+
108+TEST_F(ScreencastStream, exception_does_not_leave_wait_handle_hanging)
109+{
110+ struct FailingBufferFactory : mcl::ClientBufferFactory
111+ {
112+ std::shared_ptr<mcl::ClientBuffer> create_buffer(
113+ std::shared_ptr<MirBufferPackage> const&, geom::Size, MirPixelFormat)
114+ {
115+ if (fail)
116+ throw std::runtime_error("monkey wrench");
117+ else
118+ return nullptr;
119+ }
120+
121+ void start_failing()
122+ {
123+ fail = true;
124+ }
125+
126+ private:
127+ bool fail = false;
128+ };
129+
130+ struct BufferCreationFailingPlatform : mir_test_framework::StubClientPlatform
131+ {
132+ BufferCreationFailingPlatform(
133+ std::shared_ptr<mcl::ClientBufferFactory> const& factory, mcl::ClientContext* context) :
134+ StubClientPlatform(context),
135+ factory(factory)
136+ {
137+ }
138+ std::shared_ptr<mcl::ClientBufferFactory> create_buffer_factory()
139+ {
140+ return factory;
141+ }
142+ std::shared_ptr<mcl::ClientBufferFactory> const factory;
143+ };
144+
145+ EXPECT_CALL(mock_protobuf_server, screencast_buffer(_,_,_))
146+ .WillOnce(Invoke(
147+ [](mp::ScreencastId const*, mp::Buffer* b, google::protobuf::Closure* c)
148+ {
149+ int different_id = 33;
150+ b->set_buffer_id(different_id);
151+ EXPECT_THROW({ c->Run(); }, std::runtime_error);
152+ }));
153+ auto factory = std::make_shared<FailingBufferFactory>();
154+ auto platform = std::make_shared<BufferCreationFailingPlatform>(factory, nullptr);
155+
156+ mcl::ScreencastStream stream(nullptr, mock_protobuf_server, platform, response);
157+ factory->start_failing();
158+
159+ auto wh = stream.next_buffer([]{});
160+ wh->wait_for_all();
161+ EXPECT_FALSE(wh->is_pending());
162+}

Subscribers

People subscribed via source and target branches