{"id":12,"date":"2009-07-22T17:42:11","date_gmt":"2009-07-22T15:42:11","guid":{"rendered":"http:\/\/blogs.igalia.com\/xrcalvar\/?p=10"},"modified":"2009-07-22T17:42:11","modified_gmt":"2009-07-22T15:42:11","slug":"state-pattern-fixed-in-the-mafw-gst-renderer","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/xrcalvar\/2009\/07\/22\/state-pattern-fixed-in-the-mafw-gst-renderer\/","title":{"rendered":"State pattern fixed in the mafw-gst-renderer"},"content":{"rendered":"<p>I had this post planned for a long time, but here it goes.<\/p>\n<p>When we were developing the renderer some time ago, we saw that code was getting out of control because handling state changes was becoming hell, so we decided to rework it applying the <a href=\"http:\/\/en.wikipedia.org\/wiki\/State_pattern\">State Pattern<\/a>. Though <a href=\"http:\/\/zee-nix.blogspot.com\/\">Zeenix<\/a> thinks it was my <a href=\"http:\/\/madsgroup.org\/staff\/laura\/\">wife<\/a>&#8216;s idea, it was actually <a href=\"http:\/\/blogs.igalia.com\/itoral\/\">Iago<\/a>&#8216;s.<\/p>\n<p>The other day I found a function that was sinning against that pattern. It was <code>_update_playcount_cb<\/code>. When it was written, the call had been place in a central point where every media change going thru, but it was a bit ugly as it was using an <i>if statement<\/i> checking for the current state. This application of the state pattern is not completely canonical as we keep the current state but only because <i>state classes are stateless<\/i> and we want to keep them as <a href=\"http:\/\/en.wikipedia.org\/wiki\/Singleton_pattern\">Singleton&#8217;s<\/a>, so the easiest way was keeping that variable to point the current state, but of course using it in an if statement is ugly.<\/p>\n<p>Fortunately, I checked where it was needed to call that function and it saw it was in couple of places, so I reworked the code a bit and place the calls in the exact places where it was needed, so i didn&#8217;t need to make that function support the state pattern (in fact it would have been stupid).<\/p>\n<p>But this state pattern still needs some finetuning. We&#8217;d need to remove the <i>worker<\/i> and increase the number of states and add substates to control for example the buffering and hide properly some <a href=\"http:\/\/gstreamer.freedesktop.org\/\">GStreamer<\/a> state changes that would make the code easier to understand and maintain.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had this post planned for a long time, but here it goes. When we were developing the renderer some time ago, we saw that code was getting out of control because handling state changes was becoming hell, so we &hellip; <a href=\"https:\/\/blogs.igalia.com\/xrcalvar\/2009\/07\/22\/state-pattern-fixed-in-the-mafw-gst-renderer\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4,7,8,9,11,6],"tags":[19],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-gnome","category-igaliacom","category-planet-gnome","category-planet-gpul","category-planet-igalia","category-planeta-gnome-hispano","category-planets","tag-mafw"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":0,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}