Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-extension.git] / dali-extension / video-player / ecore-wl / tizen-video-player-ecore-wl.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <tizen-video-player.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/stage.h>
23 #include <dali/devel-api/threading/mutex.h>
24 #include <dali/integration-api/debug.h>
25 #include <system_info.h>
26
27 // INTERNAL INCLUDES
28
29 // The plugin factories
30 extern "C" DALI_EXPORT_API Dali::VideoPlayerPlugin* CreateVideoPlayerPlugin( void )
31 {
32   return new Dali::Plugin::TizenVideoPlayer;
33 }
34
35 extern "C" DALI_EXPORT_API void DestroyVideoPlayerPlugin( Dali::VideoPlayerPlugin* plugin )
36 {
37   if( plugin != NULL )
38   {
39     delete plugin;
40   }
41 }
42
43 namespace Dali
44 {
45
46 namespace Plugin
47 {
48
49 namespace
50 {
51
52 const int TIMER_INTERVAL( 20 );
53
54 static void MediaPacketVideoDecodedCb( media_packet_h packet, void* user_data )
55 {
56   TizenVideoPlayer* player = static_cast< TizenVideoPlayer* >( user_data );
57
58   if( player == NULL )
59   {
60     DALI_LOG_ERROR( "Decoded callback got Null pointer as user_data.\n" );
61     return;
62   }
63
64   player->PushPacket( packet );
65 }
66
67 static void EmitPlaybackFinishedSignal( void* user_data )
68 {
69   TizenVideoPlayer* player = static_cast< TizenVideoPlayer* >( user_data );
70
71   if( player == NULL )
72   {
73     DALI_LOG_ERROR( "Decoded callback got Null pointer as user_data.\n" );
74     return;
75   }
76
77   if( !player->mFinishedSignal.Empty() )
78   {
79     DALI_LOG_ERROR( "EmitPlaybackFinishedSignal.3\n" );
80     player->mFinishedSignal.Emit();
81   }
82
83   player->Stop();
84 }
85
86 // ToDo: VD player_set_play_position() doesn't work when callback pointer is NULL.
87 // We should check whether this callback is needed in platform.
88 static void PlayerSeekCompletedCb( void* data )
89 {
90 }
91
92 void LogPlayerError( int error )
93 {
94   if( error != PLAYER_ERROR_NONE )
95   {
96     switch( error )
97     {
98       case PLAYER_ERROR_OUT_OF_MEMORY:
99       {
100         DALI_LOG_ERROR( "Player error: Out of memory\n" );
101         return;
102       }
103       case PLAYER_ERROR_INVALID_PARAMETER:
104       {
105         DALI_LOG_ERROR( "Player error: Invalid parameter\n" );
106         return;
107       }
108       case PLAYER_ERROR_NO_SUCH_FILE:
109       {
110         DALI_LOG_ERROR( "Player error: No such file\n" );
111         return;
112       }
113       case PLAYER_ERROR_INVALID_OPERATION:
114       {
115         DALI_LOG_ERROR( "Player error: Invalid operation\n" );
116         return;
117       }
118       case PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE:
119       {
120         DALI_LOG_ERROR( "Player error: No space on device\n" );
121         return;
122       }
123       case PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE:
124       {
125         DALI_LOG_ERROR( "Player error: Not supported feature on device\n" );
126         return;
127       }
128       case PLAYER_ERROR_SEEK_FAILED:
129       {
130         DALI_LOG_ERROR( "Player error: Seek failed\n" );
131         return;
132       }
133       case PLAYER_ERROR_INVALID_STATE:
134       {
135         DALI_LOG_ERROR( "Player error: Invalid state\n" );
136         return;
137       }
138       case PLAYER_ERROR_NOT_SUPPORTED_FILE:
139       {
140         DALI_LOG_ERROR( "Player error: Not supported file\n" );
141         return;
142       }
143       case PLAYER_ERROR_INVALID_URI:
144       {
145         DALI_LOG_ERROR( "Player error: Invalid uri\n" );
146         return;
147       }
148       case PLAYER_ERROR_SOUND_POLICY:
149       {
150         DALI_LOG_ERROR( "Player error: Sound policy\n" );
151         return;
152       }
153       case PLAYER_ERROR_CONNECTION_FAILED:
154       {
155         DALI_LOG_ERROR( "Player error: Connection failed\n" );
156         return;
157       }
158       case PLAYER_ERROR_VIDEO_CAPTURE_FAILED:
159       {
160         DALI_LOG_ERROR( "Player error: Video capture failed\n" );
161         return;
162       }
163       case PLAYER_ERROR_DRM_EXPIRED:
164       {
165         DALI_LOG_ERROR( "Player error: DRM expired\n" );
166         return;
167       }
168       case PLAYER_ERROR_DRM_NO_LICENSE:
169       {
170         DALI_LOG_ERROR( "Player error: No license\n" );
171         return;
172       }
173       case PLAYER_ERROR_DRM_FUTURE_USE:
174       {
175         DALI_LOG_ERROR( "Player error: License for future use\n" );
176         return;
177       }
178       case PLAYER_ERROR_DRM_NOT_PERMITTED:
179       {
180         DALI_LOG_ERROR( "Player error: Format not permitted\n" );
181         return;
182       }
183       case PLAYER_ERROR_RESOURCE_LIMIT:
184       {
185         DALI_LOG_ERROR( "Player error: Resource limit\n" );
186         return;
187       }
188       case PLAYER_ERROR_PERMISSION_DENIED:
189       {
190         DALI_LOG_ERROR( "Player error: Permission denied\n" );
191         return;
192       }
193       case PLAYER_ERROR_SERVICE_DISCONNECTED:
194       {
195         DALI_LOG_ERROR( "Player error: Service disconnected\n" );
196         return;
197       }
198       case PLAYER_ERROR_BUFFER_SPACE:
199       {
200         DALI_LOG_ERROR( "Player error: Buffer space\n" );
201         return;
202       }
203     }
204   }
205 }
206
207 } // unnamed namespace
208
209 TizenVideoPlayer::TizenVideoPlayer()
210 : mUrl(),
211   mPlayer( NULL ),
212   mPlayerState( PLAYER_STATE_NONE ),
213   mTbmSurface( NULL ),
214   mPacket( NULL ),
215   mNativeImageSourcePtr( NULL ),
216   mTimer(),
217   mBackgroundColor( Dali::Vector4( 1.0f, 1.0f, 1.0f, 0.0f ) ),
218   mTargetType( NativeImage ),
219   mPacketMutex(),
220   mPacketVector(),
221   mEcoreWlWindow( NULL ),
222   mAlphaBitChanged( false ),
223   mCodecType( PLAYER_CODEC_TYPE_DEFAULT ),
224   mStreamInfo( NULL ),
225   mStreamType( SOUND_STREAM_TYPE_MEDIA )
226 {
227 }
228
229 TizenVideoPlayer::~TizenVideoPlayer()
230 {
231   DestroyPlayer();
232 }
233
234 void TizenVideoPlayer::GetPlayerState( player_state_e* state ) const
235 {
236   if( mPlayer != NULL && player_get_state( mPlayer, state ) != PLAYER_ERROR_NONE )
237   {
238     DALI_LOG_ERROR( "player_get_state error: Invalid parameter\n" );
239     *state = PLAYER_STATE_NONE;
240   }
241 }
242
243 void TizenVideoPlayer::SetUrl( const std::string& url )
244 {
245   if( mUrl != url )
246   {
247     int error = PLAYER_ERROR_NONE;
248
249     mUrl = url;
250
251     GetPlayerState( &mPlayerState );
252
253     if( mPlayerState != PLAYER_STATE_NONE && mPlayerState != PLAYER_STATE_IDLE )
254     {
255
256       if( mNativeImageSourcePtr )
257       {
258         error = player_unset_media_packet_video_frame_decoded_cb( mPlayer );
259         LogPlayerError( error );
260       }
261
262       Stop();
263
264       error = player_unprepare( mPlayer );
265       LogPlayerError( error );
266
267       if( mNativeImageSourcePtr )
268       {
269         error = player_set_media_packet_video_frame_decoded_cb( mPlayer, MediaPacketVideoDecodedCb, this );
270         LogPlayerError( error );
271       }
272       else
273       {
274         int width, height;
275         ecore_wl_screen_size_get( &width, &height );
276         error = player_set_ecore_wl_display( mPlayer, PLAYER_DISPLAY_TYPE_OVERLAY, mEcoreWlWindow, 0, 0, width, height );
277         LogPlayerError( error );
278       }
279
280       GetPlayerState( &mPlayerState );
281       LogPlayerError( error );
282     }
283
284     if( mPlayerState == PLAYER_STATE_IDLE )
285     {
286       error = player_set_uri( mPlayer, mUrl.c_str() );
287       LogPlayerError( error );
288
289       error = player_prepare( mPlayer );
290       LogPlayerError( error );
291     }
292   }
293 }
294
295 std::string TizenVideoPlayer::GetUrl()
296 {
297   return mUrl;
298 }
299
300 void TizenVideoPlayer::SetRenderingTarget( Any target )
301 {
302   DestroyPlayer();
303
304   mNativeImageSourcePtr = NULL;
305   mEcoreWlWindow = NULL;
306
307   if( target.GetType() == typeid( Dali::NativeImageSourcePtr ) )
308   {
309     mTargetType = TizenVideoPlayer::NativeImage;
310
311     Dali::NativeImageSourcePtr nativeImageSourcePtr = AnyCast< Dali::NativeImageSourcePtr >( target );
312
313     InitializeTextureStreamMode( nativeImageSourcePtr );
314   }
315   else if( target.GetType() == typeid( Ecore_Wl_Window* ) )
316   {
317     mTargetType = TizenVideoPlayer::WindowSurface;
318
319     Ecore_Wl_Window* nativeWindow = Dali::AnyCast< Ecore_Wl_Window* >( target );
320     InitializeUnderlayMode( nativeWindow );
321   }
322   else
323   {
324     DALI_LOG_ERROR( "Video rendering target is unknown\n" );
325   }
326 }
327
328 void TizenVideoPlayer::SetLooping( bool looping )
329 {
330   GetPlayerState( &mPlayerState );
331
332   if( mPlayerState != PLAYER_STATE_NONE )
333   {
334     int error = player_set_looping( mPlayer, looping );
335     LogPlayerError( error );
336   }
337 }
338
339 bool TizenVideoPlayer::IsLooping()
340 {
341   GetPlayerState( &mPlayerState );
342
343   bool looping = false;
344   if( mPlayerState != PLAYER_STATE_NONE )
345   {
346     int error = player_is_looping( mPlayer, &looping );
347     LogPlayerError( error );
348   }
349
350   return looping;
351 }
352
353 void TizenVideoPlayer::Play()
354 {
355   GetPlayerState( &mPlayerState );
356
357   if( mPlayerState == PLAYER_STATE_READY || mPlayerState == PLAYER_STATE_PAUSED )
358   {
359     if( mNativeImageSourcePtr != NULL && mTimer )
360     {
361       mTimer.Start();
362     }
363
364     int error = player_start( mPlayer );
365     LogPlayerError( error );
366   }
367 }
368
369 void TizenVideoPlayer::Pause()
370 {
371   GetPlayerState( &mPlayerState );
372
373   if( mPlayerState == PLAYER_STATE_PLAYING )
374   {
375     int error = player_pause( mPlayer );
376     LogPlayerError( error );
377
378     if( mNativeImageSourcePtr != NULL && mTimer )
379     {
380       mTimer.Stop();
381       DestroyPackets();
382     }
383   }
384 }
385
386 void TizenVideoPlayer::Stop()
387 {
388   GetPlayerState( &mPlayerState );
389
390   if( mPlayerState == PLAYER_STATE_PLAYING || mPlayerState == PLAYER_STATE_PAUSED )
391   {
392     int error = player_stop( mPlayer );
393     LogPlayerError( error );
394   }
395
396   if( mNativeImageSourcePtr != NULL && mTimer )
397   {
398     mTimer.Stop();
399     DestroyPackets();
400   }
401 }
402
403 void TizenVideoPlayer::SetMute( bool muted )
404 {
405   GetPlayerState( &mPlayerState );
406
407   if( mPlayerState == PLAYER_STATE_IDLE ||
408       mPlayerState == PLAYER_STATE_READY ||
409       mPlayerState == PLAYER_STATE_PLAYING ||
410       mPlayerState == PLAYER_STATE_PAUSED
411     )
412   {
413     int error = player_set_mute( mPlayer, muted );
414     LogPlayerError( error );
415   }
416 }
417
418 bool TizenVideoPlayer::IsMuted()
419 {
420   GetPlayerState( &mPlayerState );
421   bool muted = false;
422
423    if( mPlayerState == PLAYER_STATE_IDLE ||
424       mPlayerState == PLAYER_STATE_READY ||
425       mPlayerState == PLAYER_STATE_PLAYING ||
426       mPlayerState == PLAYER_STATE_PAUSED
427     )
428   {
429     int error = player_is_muted( mPlayer, &muted );
430     LogPlayerError( error );
431   }
432
433   return muted;
434 }
435
436 void TizenVideoPlayer::SetVolume( float left, float right )
437 {
438   GetPlayerState( &mPlayerState );
439
440   int error = player_set_volume( mPlayer, left, right );
441   LogPlayerError( error );
442 }
443
444 void TizenVideoPlayer::GetVolume( float& left, float& right )
445 {
446   GetPlayerState( &mPlayerState );
447
448   int error = player_get_volume( mPlayer, &left, &right );
449   LogPlayerError( error );
450 }
451
452 void TizenVideoPlayer::SetPlayPosition( int millisecond )
453 {
454   int error;
455
456   GetPlayerState( &mPlayerState );
457
458   if( mPlayerState == PLAYER_STATE_READY ||
459       mPlayerState == PLAYER_STATE_PLAYING ||
460       mPlayerState == PLAYER_STATE_PAUSED
461   )
462   {
463     error = player_set_play_position( mPlayer, millisecond, false, PlayerSeekCompletedCb, NULL );
464     LogPlayerError( error );
465   }
466 }
467
468 int TizenVideoPlayer::GetPlayPosition()
469 {
470   int error;
471   int millisecond = 0;
472
473   GetPlayerState( &mPlayerState );
474
475   if( mPlayerState == PLAYER_STATE_IDLE ||
476       mPlayerState == PLAYER_STATE_READY ||
477       mPlayerState == PLAYER_STATE_PLAYING ||
478       mPlayerState == PLAYER_STATE_PAUSED
479   )
480   {
481     error = player_get_play_position( mPlayer, &millisecond );
482     LogPlayerError( error );
483   }
484
485   return millisecond;
486 }
487
488 void TizenVideoPlayer::SetDisplayRotation( Dali::VideoPlayerPlugin::DisplayRotation rotation )
489 {
490   if( mNativeImageSourcePtr != NULL )
491   {
492     DALI_LOG_ERROR( "SetDisplayRotation is only for window rendering target.\n" );
493     return;
494   }
495
496   int error;
497   if( mPlayerState != PLAYER_STATE_NONE )
498   {
499     error = player_set_display_rotation( mPlayer, static_cast< player_display_rotation_e >( rotation ) );
500     LogPlayerError( error );
501   }
502 }
503
504 Dali::VideoPlayerPlugin::DisplayRotation TizenVideoPlayer::GetDisplayRotation()
505 {
506   if( mNativeImageSourcePtr != NULL )
507   {
508     DALI_LOG_ERROR( "GetDisplayRotation is only for window rendering target.\n" );
509     return Dali::VideoPlayerPlugin::ROTATION_NONE;
510   }
511
512   int error;
513   player_display_rotation_e rotation = PLAYER_DISPLAY_ROTATION_NONE;
514   if( mPlayerState != PLAYER_STATE_NONE )
515   {
516     error = player_get_display_rotation( mPlayer, &rotation );
517     LogPlayerError( error );
518   }
519   return static_cast< Dali::VideoPlayerPlugin::DisplayRotation >( rotation );
520 }
521
522 Dali::VideoPlayerPlugin::VideoPlayerSignalType& TizenVideoPlayer::FinishedSignal()
523 {
524   return mFinishedSignal;
525 }
526
527 void TizenVideoPlayer::InitializeTextureStreamMode( Dali::NativeImageSourcePtr nativeImageSourcePtr )
528 {
529   int error;
530
531   mNativeImageSourcePtr = nativeImageSourcePtr;
532
533   if( mAlphaBitChanged )
534   {
535     ecore_wl_window_alpha_set( mEcoreWlWindow, false );
536     mAlphaBitChanged = false;
537   }
538
539   if( mPlayerState == PLAYER_STATE_NONE )
540   {
541     error = player_create( &mPlayer );
542     LogPlayerError( error );
543   }
544
545   GetPlayerState( &mPlayerState );
546
547   if( mPlayerState == PLAYER_STATE_IDLE )
548   {
549     error = player_set_completed_cb( mPlayer, EmitPlaybackFinishedSignal, this );
550     LogPlayerError( error );
551
552     error = player_set_media_packet_video_frame_decoded_cb( mPlayer, MediaPacketVideoDecodedCb, this );
553     LogPlayerError( error );
554
555     error = sound_manager_create_stream_information( mStreamType, NULL, NULL, &mStreamInfo );
556     LogPlayerError( error );
557
558     error = player_set_sound_stream_info( mPlayer, mStreamInfo );
559     LogPlayerError( error );
560
561     error = player_set_display_mode( mPlayer, PLAYER_DISPLAY_MODE_FULL_SCREEN );
562     LogPlayerError( error );
563
564     error = player_set_display( mPlayer, PLAYER_DISPLAY_TYPE_NONE, NULL );
565     LogPlayerError( error );
566
567     error = player_set_display_visible( mPlayer, true );
568     LogPlayerError( error );
569
570     mTimer = Dali::Timer::New( TIMER_INTERVAL );
571     mTimer.TickSignal().Connect( this, &TizenVideoPlayer::Update );
572   }
573 }
574
575 void TizenVideoPlayer::InitializeUnderlayMode( Ecore_Wl_Window* ecoreWlWindow )
576 {
577   int error;
578   if( mPlayerState == PLAYER_STATE_NONE )
579   {
580     error = player_create( &mPlayer );
581     LogPlayerError( error );
582   }
583
584   GetPlayerState( &mPlayerState );
585   mEcoreWlWindow = ecoreWlWindow;
586
587   if( mPlayerState == PLAYER_STATE_IDLE )
588   {
589     error = player_set_completed_cb( mPlayer, EmitPlaybackFinishedSignal, this );
590     LogPlayerError( error );
591
592     error = sound_manager_create_stream_information( mStreamType, NULL, NULL, &mStreamInfo );
593     LogPlayerError( error );
594
595     error = player_set_sound_stream_info( mPlayer, mStreamInfo );
596     LogPlayerError( error );
597
598     error = player_set_display_mode( mPlayer, PLAYER_DISPLAY_MODE_DST_ROI );
599     LogPlayerError( error );
600
601     error = player_set_display_roi_area( mPlayer, 0, 0, 1, 1 );
602
603     int width, height;
604     ecore_wl_screen_size_get( &width, &height );
605     ecore_wl_window_alpha_set( mEcoreWlWindow, false );
606
607     error = player_set_ecore_wl_display( mPlayer, PLAYER_DISPLAY_TYPE_OVERLAY, mEcoreWlWindow, 0, 0, width, height );
608     LogPlayerError( error );
609
610     error = player_set_display_visible( mPlayer, true );
611     LogPlayerError( error );
612   }
613 }
614
615 bool TizenVideoPlayer::Update()
616 {
617   Dali::Mutex::ScopedLock lock( mPacketMutex );
618
619   int error;
620
621   if( mPacket != NULL )
622   {
623     error = media_packet_destroy( mPacket );
624     if( error != MEDIA_PACKET_ERROR_NONE )
625     {
626       DALI_LOG_ERROR( "Media packet destroy error: %d\n", error );
627     }
628     mPacket = NULL;
629   }
630
631   if( !mPacketVector.Empty() )
632   {
633     mPacket = static_cast< media_packet_h >( mPacketVector[0] );
634     mPacketVector.Remove( mPacketVector.Begin() );
635   }
636
637   if( mPacket == NULL )
638   {
639     return true;
640   }
641
642   error = media_packet_get_tbm_surface( mPacket, &mTbmSurface );
643   if( error != MEDIA_PACKET_ERROR_NONE )
644   {
645     media_packet_destroy( mPacket );
646     mPacket = NULL;
647     DALI_LOG_ERROR( " error: %d\n", error );
648     return true;
649   }
650
651   Any source( mTbmSurface );
652   mNativeImageSourcePtr->SetSource( source );
653   Dali::Stage::GetCurrent().KeepRendering( 0.0f );
654
655   return true;
656 }
657
658 void TizenVideoPlayer::DestroyPackets()
659 {
660   int error;
661   if( mPacket != NULL )
662   {
663     error = media_packet_destroy( mPacket );
664     DALI_LOG_ERROR( "Media packet destroy error: %d\n", error );
665     mPacket = NULL;
666   }
667
668   for(unsigned int i = 0; i < mPacketVector.Size(); ++i)
669   {
670     mPacket = static_cast< media_packet_h >( mPacketVector[i] );
671     error = media_packet_destroy( mPacket );
672     DALI_LOG_ERROR( "Media packet destroy error: %d\n", error );
673     mPacket = NULL;
674   }
675   mPacketVector.Clear();
676 }
677
678 void TizenVideoPlayer::PushPacket( media_packet_h packet )
679 {
680   Dali::Mutex::ScopedLock lock( mPacketMutex );
681   mPacketVector.PushBack( packet );
682 }
683
684 void TizenVideoPlayer::SetDisplayArea( DisplayArea area )
685 {
686   GetPlayerState( &mPlayerState );
687
688   if( mNativeImageSourcePtr != NULL )
689   {
690     DALI_LOG_ERROR( "SetDisplayArea is only for window surface target.\n" );
691     return;
692   }
693
694   if( mPlayerState == PLAYER_STATE_IDLE ||
695       mPlayerState == PLAYER_STATE_READY ||
696       mPlayerState == PLAYER_STATE_PLAYING ||
697       mPlayerState == PLAYER_STATE_PAUSED
698
699   )
700   {
701     area.x = ( area.x < 0 ) ? 0: area.x;
702     area.y = ( area.y < 0 ) ? 0: area.y;
703     int error = player_set_display_roi_area( mPlayer, area.x, area.y, area.width, area.height );
704     LogPlayerError( error );
705   }
706 }
707
708 void TizenVideoPlayer::Forward( int millisecond )
709 {
710   int error;
711
712   GetPlayerState( &mPlayerState );
713
714   if( mPlayerState == PLAYER_STATE_READY ||
715       mPlayerState == PLAYER_STATE_PLAYING ||
716       mPlayerState == PLAYER_STATE_PAUSED
717   )
718   {
719     int currentPosition = 0;
720     int nextPosition = 0;
721
722     error = player_get_play_position( mPlayer, &currentPosition );
723     LogPlayerError( error );
724
725     nextPosition = currentPosition + millisecond;
726
727     error = player_set_play_position( mPlayer, nextPosition, false, PlayerSeekCompletedCb, NULL );
728     LogPlayerError( error );
729   }
730 }
731
732 void TizenVideoPlayer::Backward( int millisecond )
733 {
734   int error;
735
736   GetPlayerState( &mPlayerState );
737
738   if( mPlayerState == PLAYER_STATE_READY ||
739       mPlayerState == PLAYER_STATE_PLAYING ||
740       mPlayerState == PLAYER_STATE_PAUSED
741   )
742   {
743     int currentPosition = 0;
744     int nextPosition = 0;
745
746     error = player_get_play_position( mPlayer, &currentPosition );
747     LogPlayerError( error );
748
749     nextPosition = currentPosition - millisecond;
750     nextPosition = ( nextPosition < 0 )? 0 : nextPosition;
751
752     error = player_set_play_position( mPlayer, nextPosition, false, PlayerSeekCompletedCb, NULL );
753     LogPlayerError( error );
754   }
755 }
756
757 bool TizenVideoPlayer::IsVideoTextureSupported()
758 {
759   bool featureFlag = true;
760   int error = SYSTEM_INFO_ERROR_NONE;
761
762   error = system_info_get_platform_bool( "tizen.org/feature/multimedia.raw_video", &featureFlag );
763
764   if( error != SYSTEM_INFO_ERROR_NONE )
765   {
766     DALI_LOG_ERROR( "Plugin can't check platform feature\n" );
767     return false;
768   }
769
770   return featureFlag;
771 }
772
773 void TizenVideoPlayer::DestroyPlayer()
774 {
775   int error;
776   if( mPlayerState != PLAYER_STATE_NONE )
777   {
778     GetPlayerState( &mPlayerState );
779
780     if( mPlayerState != PLAYER_STATE_IDLE )
781     {
782       Stop();
783       error = player_unprepare( mPlayer );
784       LogPlayerError( error );
785     }
786
787     error = player_destroy( mPlayer );
788     LogPlayerError( error );
789
790     error = sound_manager_destroy_stream_information(mStreamInfo);
791     LogPlayerError( error );
792
793     mPlayerState = PLAYER_STATE_NONE;
794     mPlayer = NULL;
795     mUrl = "";
796   }
797 }
798
799 void TizenVideoPlayer::SetCodecType( Dali::VideoPlayerPlugin::CodecType type )
800 {
801   int error;
802   if( mPlayerState != PLAYER_STATE_NONE )
803   {
804     GetPlayerState( &mPlayerState );
805
806     if( mPlayerState == PLAYER_STATE_IDLE )
807     {
808       error = player_set_codec_type( mPlayer, PLAYER_STREAM_TYPE_VIDEO, static_cast< player_codec_type_e >( type ) );
809       LogPlayerError( error );
810
811       if( error == PLAYER_ERROR_INVALID_OPERATION )
812       {
813         DALI_LOG_ERROR( "The target should not support the codec type\n" );
814       }
815       error = player_get_codec_type( mPlayer, PLAYER_STREAM_TYPE_VIDEO, &mCodecType );
816       LogPlayerError( error );
817     }
818   }
819 }
820
821 Dali::VideoPlayerPlugin::CodecType TizenVideoPlayer::GetCodecType() const
822 {
823   return static_cast< Dali::VideoPlayerPlugin::CodecType >( mCodecType );
824 }
825
826 void TizenVideoPlayer::SetDisplayMode( Dali::VideoPlayerPlugin::DisplayMode::Type mode )
827 {
828   int error;
829   error = player_set_display_mode( mPlayer, static_cast< player_display_mode_e >( mode ) );
830   LogPlayerError( error );
831 }
832
833 Dali::VideoPlayerPlugin::DisplayMode::Type TizenVideoPlayer::GetDisplayMode() const
834 {
835   player_display_mode_e mode;
836   player_get_display_mode( mPlayer, &mode );
837   return static_cast< Dali::VideoPlayerPlugin::DisplayMode::Type >( mode );
838 }
839
840
841 } // namespace Plugin
842 } // namespace Dali;