| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "bcm_host.h" |
| 29 | #include "mmal.h" |
| 30 | #include "util/mmal_graph.h" |
| 31 | #include "util/mmal_default_components.h" |
| 32 | #include "util/mmal_util_params.h" |
| 33 | #include <stdio.h> |
| 34 | |
| 35 | #define CHECK_STATUS(status, msg) if (status != MMAL_SUCCESS) { fprintf(stderr, msg"\n"); goto error; } |
| 36 | |
| 37 | int main(int argc, char **argv) |
| 38 | { |
| 39 | MMAL_STATUS_T status; |
| 40 | MMAL_GRAPH_T *graph = 0; |
| 41 | MMAL_COMPONENT_T *reader = 0, *decoder = 0, *renderer = 0; |
| 42 | |
| 43 | if (argc < 2) |
| 44 | { |
| 45 | fprintf(stderr, "invalid arguments\n" ); |
| 46 | return -1; |
| 47 | } |
| 48 | |
| 49 | bcm_host_init(); |
| 50 | |
| 51 | /* Create the graph */ |
| 52 | status = mmal_graph_create(&graph, 0); |
| 53 | CHECK_STATUS(status, "failed to create graph" ); |
| 54 | |
| 55 | /* Add the components */ |
| 56 | status = mmal_graph_new_component(graph, MMAL_COMPONENT_DEFAULT_CONTAINER_READER, &reader); |
| 57 | CHECK_STATUS(status, "failed to create reader" ); |
| 58 | |
| 59 | status = mmal_graph_new_component(graph, MMAL_COMPONENT_DEFAULT_VIDEO_DECODER, &decoder); |
| 60 | CHECK_STATUS(status, "failed to create decoder" ); |
| 61 | |
| 62 | status = mmal_graph_new_component(graph, MMAL_COMPONENT_DEFAULT_VIDEO_RENDERER, &renderer); |
| 63 | CHECK_STATUS(status, "failed to create renderer" ); |
| 64 | |
| 65 | /* Configure the reader using the given URI */ |
| 66 | status = mmal_util_port_set_uri(reader->control, argv[1]); |
| 67 | CHECK_STATUS(status, "failed to set uri" ); |
| 68 | |
| 69 | /* connect them up - this propagates port settings from outputs to inputs */ |
| 70 | status = mmal_graph_new_connection(graph, reader->output[0], decoder->input[0], 0, NULL); |
| 71 | CHECK_STATUS(status, "failed to connect reader to decoder" ); |
| 72 | status = mmal_graph_new_connection(graph, decoder->output[0], renderer->input[0], 0, NULL); |
| 73 | CHECK_STATUS(status, "failed to connect decoder to renderer" ); |
| 74 | |
| 75 | /* Start playback */ |
| 76 | fprintf(stderr, "start playback\n" ); |
| 77 | status = mmal_graph_enable(graph, NULL, NULL); |
| 78 | CHECK_STATUS(status, "failed to enable graph" ); |
| 79 | |
| 80 | sleep(5); |
| 81 | |
| 82 | /* Stop everything */ |
| 83 | fprintf(stderr, "stop playback\n" ); |
| 84 | mmal_graph_disable(graph); |
| 85 | |
| 86 | error: |
| 87 | /* Cleanup everything */ |
| 88 | if (reader) |
| 89 | mmal_component_release(reader); |
| 90 | if (decoder) |
| 91 | mmal_component_release(decoder); |
| 92 | if (renderer) |
| 93 | mmal_component_release(renderer); |
| 94 | if (graph) |
| 95 | mmal_graph_destroy(graph); |
| 96 | |
| 97 | return status == MMAL_SUCCESS ? 0 : -1; |
| 98 | } |
| 99 | |