Пример #1
0
MainWindow::MainWindow()
{
    //CREATION DU MENU
    setWindowTitle("CalcUTC");
    this->size_min();
    QMenu *menuOption = menuBar()->addMenu("&Option");
    QAction *actionQuitter = new QAction("&Quitter", this); //AJOUT DE QUITTER
    menuOption->addAction(actionQuitter);
    QAction *actionProgEdit = new QAction("Nouveau programme", this); // Ajout d'une action créer nouveau programme qui ouvre un QEDITTEXT
    menuOption->addAction(actionProgEdit);

    QMenu *menuAffichage = menuBar()->addMenu("&Affichage");
    QAction *actionClavier = new QAction("&Clavier", this);   //OPTION D'AFFICHAGE DU CLAVIER ET DES FONCTIONS SCIENTIFIQUES
    menuAffichage->addAction(actionClavier);
    QAction *actionScientifique = new QAction("&Mode scientifique", this);
    menuAffichage->addAction(actionScientifique);
    QAction *actionProg = new QAction("&Gestion Programme",this);
    menuAffichage->addAction(actionProg);


    QAction *actionRedo = new QAction("&Redo", this);  // AJOUT DU "Redo"
    menuOption->addAction(actionRedo);
    actionRedo->setIcon(QIcon("\\Users\\Adrien\\Documents\\Adrien\\UTC\\GI 02\\LO21\\Projet\\version finale\\projet_1_0\\images/arrow_redo.png"));
    actionRedo->setShortcut(QKeySequence(tr("Ctrl+y")));

    QAction *actionUndo = new QAction("&Undo", this);  // AJOUT DU "Undo"
    menuOption->addAction(actionUndo);
    actionUndo->setIcon(QIcon("\\Users\\Adrien\\Documents\\Adrien\\UTC\\GI 02\\LO21\\Projet\\version finale\\projet_1_0\\images/arrow_undo.png"));
    actionUndo->setShortcut(QKeySequence(tr("Ctrl+z")));

    QMenu *menuAide = menuBar()->addMenu("&Aide");
    QAction *actionAPropos = new QAction("&A propos", this);  // AJOUT DU "A PROPOS"
    menuAide->addAction(actionAPropos);

    // GESTION DES SIGNAUX ET SLOTS DU MENU
    connect(actionQuitter, SIGNAL(triggered()), qApp, SLOT(quit()));
    actionQuitter->setShortcut(QKeySequence("Escape"));
    connect(actionScientifique, SIGNAL(triggered()), this, SLOT(afficher_scientique()));
    connect(actionClavier, SIGNAL(triggered()), this, SLOT(afficher_clavier()));
    actionClavier->setCheckable(true);
    actionScientifique->setCheckable(true);
    // CONNECT DU PROGEDIT

    connect(actionProg,SIGNAL(triggered(bool)), this, SLOT(openProgWindow()));
    connect(actionProgEdit,SIGNAL(triggered()), this, SLOT(openEditProg())); // OUVRE LE QEDITTEXT
    connect(actionAPropos,SIGNAL(triggered(bool)), this, SLOT(afficher_APropos()));


    //INITIALISATION DES OBJETS DU .h
    mainArea = new QWidget;
    mainSet = new QHBoxLayout;
    scientificPad = new scientific_pad;
    scientificPad->hide();


    keyboard = new Keyboard();
    keyboard->hide();
    controlScreen = new QWidget();
    controlScreen->setFixedSize(QSize(280, 300));

    pile = new Pile ;
    qDebug()<<pile;
    controleur = Controleur::getInstance(LiteraleManager::getInstance() , *pile) ;
    message = new QLineEdit() ;
    commande = new QLineEdit() ;
    vuePile = new QTableWidget (pile->getNbItemsToAffiche(),1) ;
    pile_create();
    topLayout = new QHBoxLayout();

    middleLayout = new QHBoxLayout();
    boutons_droits = new QVBoxLayout();

    bottomLayout = new QHBoxLayout();
    pile_plus = new QPushButton();
    pile_moins = new QPushButton();
    enter = new QPushButton();

    leftLayout = new QVBoxLayout();
    leftLayout->addWidget(vuePile);
    vuePile->setStyleSheet("background : rgba(35,141,214,45)");

    commande->setStyleSheet("background : rgba(35,141,214,45)");
    //MIDDLELAYOUT SETTINGS

    middleLayout->addLayout(leftLayout);
    middleLayout->addLayout(boutons_droits);

    boutons_droits->addWidget(pile_plus);
    boutons_droits->addWidget(pile_moins);

    //BOTTOM LAYOUT SETTINGS

    bottomLayout->addWidget(commande);
    bottomLayout->addWidget(enter);
    enter->setIcon(QIcon("\\Users\\Adrien\\Documents\\Adrien\\UTC\\GI 02\\LO21\\Projet\\version finale\\projet_1_0\\images/enter-arrow.png"));
    enter->setFlat(true);
    enter->setFocusPolicy(Qt::NoFocus);

    connect(enter,SIGNAL(clicked(bool)),this,SLOT(slot_getNextCommande()));

    //BOUTON PILE SETTINGS + CONNECT
    pile_plus->setIcon(QIcon("\\Users\\Adrien\\Documents\\Adrien\\UTC\\GI 02\\LO21\\Projet\\version finale\\projet_1_0\\images/add.png"));
    pile_plus->setFlat(true);
    pile_plus->setFocusPolicy(Qt::NoFocus);
    pile_moins->setIcon(QIcon("\\Users\\Adrien\\Documents\\Adrien\\UTC\\GI 02\\LO21\\Projet\\version finale\\projet_1_0\\images/minus.png"));
    pile_moins->setFlat(true);
    pile_moins->setFocusPolicy(Qt::NoFocus);

    connect(pile_plus,SIGNAL(clicked(bool)),pile,SLOT(aug_pile()));
    connect(pile_plus,SIGNAL(clicked(bool)),this,SLOT(pile_create()));
    connect(pile_moins,SIGNAL(clicked(bool)),pile,SLOT(dim_pile()));
    connect(pile_moins,SIGNAL(clicked(bool)),this,SLOT(pile_create()));

    // MESSAGE SETTINGS

    message->setReadOnly(true);    //empèche d'écrire dans la lineEdit
    message->setStyleSheet("background: blue; color: yellow");
    message->setAlignment(Qt::AlignHCenter);
    message->setFixedHeight(45);

    //VUE PLIE SETTINGS

    vuePile->horizontalHeader()->setVisible(false);   //enlève l'indice de col
    vuePile->horizontalHeader()->setStretchLastSection(true);   //ajuste la largeur à la fenetre
    vuePile->setSelectionMode(QAbstractItemView::NoSelection);
    vuePile->setEditTriggers(QAbstractItemView::NoEditTriggers) ;  //empèche d'écrire dans les cellules

    //SOUND_LOCK SETTINGS
    sound_lock = new QPushButton();
    sound_lock->setIcon(QIcon("\\Users\\Adrien\\Documents\\Adrien\\UTC\\GI 02\\LO21\\Projet\\version finale\\projet_1_0\\images/speaker.png"));
    sound_lock->setFlat(true);
    sound_lock->setFocusPolicy(Qt::NoFocus);
    connect(sound_lock,SIGNAL(clicked(bool)),this,SLOT(sound_disable()));

    //GESTION DES CONNECTS DU SCIENTIFIC_PAD

    connect(scientificPad->cos, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->sin, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->tan, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->arccos, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->arcsin, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->arctan, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->sqrt, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->puis, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->exp, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->ln, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->div, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    connect(scientificPad->mod, SIGNAL(clicked(bool)), this, SLOT(keyboardButtonPressed()));
    

    //GESTION DES CONNECTS DU CONTROLSCREEN
    connect(commande, SIGNAL (returnPressed()) , this , SLOT(slot_getNextCommande())) ;
    connect(pile , SIGNAL (modificationEtat()) , this, SLOT(refresh())) ;

    //GESTION DES CONNECTS DU KEYBOARD

    connect(keyboard->b1,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b2,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b3,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b4,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b5,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b6,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b7,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b8,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b9,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->b0,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->bplus,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->bmoins,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->bdiv,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->bmult,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->clear,SIGNAL(clicked(bool)),commande, SLOT(clear()));
    connect(keyboard->space,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->bComp,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->bPo,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));
    connect(keyboard->bPf,SIGNAL(clicked(bool)),this, SLOT(keyboardButtonPressed()));


    //CREATION DES LIENS ENTRE LES LAYOUTS


    mainSet->addWidget(scientificPad);
    scientificPad->setStyleSheet("background : rgba(35,141,214,45)");
    mainSet->addWidget(controlScreen);
    message->setStyleSheet("background : rgba(35,186,117,45)");
    vuePile->setStyleSheet("background : rgba(35,141,214,25)");;
    mainSet->addWidget(keyboard);
    keyboard->setStyleSheet("background : rgba(35,141,214,45)");


    topLayout->addWidget(message);
    topLayout->addWidget(sound_lock);

    LcontrolScreen = new QVBoxLayout;
    controlScreen->setLayout(LcontrolScreen);
    LcontrolScreen->addLayout(topLayout);
    LcontrolScreen->addLayout(middleLayout);
    LcontrolScreen->addLayout(bottomLayout);


    mainArea->setLayout(mainSet);
    setCentralWidget(mainArea);

    //GESTION SAUVEGARDE CONTEXTE

    connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(save_context()));
    open_context();
}
Пример #2
0
int main(int argc, char **argv)
{
    double prev_segment_time = 0;
    unsigned int output_index = 1;
    AVInputFormat *ifmt;
    AVOutputFormat *ofmt;
    AVFormatContext *ic = NULL;
    AVFormatContext *oc;
    AVStream *video_st = NULL;
    AVStream *audio_st = NULL;
    char *output_filename;
    int video_index = -1;
    int audio_index = -1;
    unsigned int first_segment = 1;
    unsigned int last_segment = 0;
    int decode_done;
    char *dot;
    int ret;
    unsigned int i;
    int remove_file;
    struct sigaction act;
    int64_t timestamp;
    int opt;
    int longindex;
    char *endptr;
    struct options_t options;

/*
Usage: recorder [options]

Options:

  -T SOCKETTIMEOUT, --sockettimeout=SOCKETTIMEOUT
                        Socket timeout (default: 30)
  -B SOCKETBUFFER, --socketbuffer=SOCKETBUFFER
                        Socket buffer in bytes(default: 1500)
  -v VERBOSE, --verbose=VERBOSE
                        Verbosity level (default: info) (ops: ['emerg',
                        'alert', 'crit', 'err', 'warning', 'notice', 'info',
                        'debug'])
  -L LOGFILE, --logfile=LOGFILE
                        Log file (default: ./recorder.log)

/root/npvr/recorder -v info -L /var/log/npvr/recorder.udctvlive00202.log -w  /mfs/npvr/storage/stream/pvr/ -C 10 -K udctvlive00202 -P http -U http://10.14.10.102:8082/stream/udctvlive00202

/mnt/mfs/npvr/storage/stream/pvr/ts/rcclive001/1359968328_10_19.ts

*/
    static const char *optstring = "i:C:K:w:s:ovh?";

    static const struct option longopts[] = {
        { "input",         required_argument, NULL, 'i' },
        { "duration",      required_argument, NULL, 'C' },
        { "key",           required_argument, NULL, 'K' },
        { "workdir",       required_argument, NULL, 'w' },
        { "stop",          no_argument,       NULL, 's' },
        { "help",          no_argument,       NULL, 'h' },
        { 0, 0, 0, 0 }
    };
    

    memset(&options, 0 ,sizeof(options));

    /* Set some defaults */
    options.segment_duration = 10;
    options.stop = 0;
    do {
        opt = getopt_long(argc, argv, optstring, longopts, &longindex );
        switch (opt) {
            case 'i':
                options.input_file = optarg;
                if (!strcmp(options.input_file, "-")) {
                    options.input_file = "pipe:";
                }
                break;

            case 'C':
                options.segment_duration = strtol(optarg, &endptr, 10);
                if (optarg == endptr || options.segment_duration < 0 || options.segment_duration == -LONG_MAX) {
                    fprintf(stderr, "Segment duration time (%s) invalid\n", optarg);
                    exit(1);
                }
                break;

            case 'K':
                options.key = optarg;
                break;

            case 'w':
                options.workdir = optarg;
                break;

            case 's':
                options.stop = 1;
                break;

            case 'h':
                display_usage();
                break;
        }
    } while (opt != -1);


    /* Check required args where set*/
    if (options.input_file == NULL) {
        fprintf(stderr, "Please specify an input file.\n");
        exit(1);
    }

    if (options.key == NULL) {
        fprintf(stderr, "Please specify an output prefix.\n");
        exit(1);
    }

    if (options.workdir == NULL) {
        fprintf(stderr, "Please working directory.\n");
        exit(1);
    }

    avformat_network_init();
    av_register_all();


    output_filename = malloc(sizeof(char) * (strlen(options.workdir) + strlen(options.key) + 15));
    if (!output_filename) {
        fprintf(stderr, "Could not allocate space for output filenames\n");
        exit(1);
    }

    ifmt = av_find_input_format("mpegts");
    if (!ifmt) {
        fprintf(stderr, "Could not find MPEG-TS demuxer\n");
        exit(1);
    }

    open_context(&ic, options.input_file, options.key, ifmt, &ofmt, &oc, &video_st, &audio_st, &video_index, &audio_index);

    timestamp = av_gettime() / 1000000;
    snprintf(output_filename, strlen(options.workdir) + strlen(options.key) + 75, "%s/ts/%s/%d_%d_%u.ts", options.workdir, options.key, (int)timestamp, (int)options.segment_duration, output_index++);
    if (avio_open(&oc->pb, output_filename, AVIO_FLAG_WRITE) < 0) {
        fprintf(stderr, "Could not open '%s'\n", output_filename);
        exit(1);
    }

    if (avformat_write_header(oc, NULL)) {
        fprintf(stderr, "Could not write mpegts header to first output file\n");
        exit(1);
    }

    /* Setup signals */
    memset(&act, 0, sizeof(act));
    act.sa_handler = &handler;

    sigaction(SIGINT, &act, NULL);
    sigaction(SIGTERM, &act, NULL);

    do {
        double segment_time = prev_segment_time;
        AVPacket packet;

        if (terminate) {
          break;
        }

        decode_done = av_read_frame(ic, &packet);
        if (decode_done < 0) {
            break;
        }

        if (av_dup_packet(&packet) < 0) {
            fprintf(stderr, "Could not duplicate packet");
            av_free_packet(&packet);
            break;
        }

        // Use video stream as time base and split at keyframes. Otherwise use audio stream
        if (packet.stream_index == video_index && (packet.flags & AV_PKT_FLAG_KEY)) {
            segment_time = packet.pts * av_q2d(video_st->time_base);
        }
        else if (video_index < 0) {
            segment_time = packet.pts * av_q2d(audio_st->time_base);
        }
        else {
          segment_time = prev_segment_time;
        }


        if (segment_time - prev_segment_time >= options.segment_duration) {
            av_write_trailer(oc);   // close ts file and free memory
            avio_flush(oc->pb);
            avio_close(oc->pb);

            timestamp = av_gettime() / 1000000;
            snprintf(output_filename, strlen(options.workdir) + strlen(options.key) + 75, "%s/ts/%s/%d_%d_%u.ts", options.workdir, options.key, (int)timestamp, (int)options.segment_duration, output_index++);
            if (avio_open(&oc->pb, output_filename, AVIO_FLAG_WRITE) < 0) {
                fprintf(stderr, "Could not open '%s'\n", output_filename);
                break;
            } 

            // Write a new header at the start of each file
            if (avformat_write_header(oc, NULL)) {
              fprintf(stderr, "Could not write mpegts header to first output file\n");
              exit(1);
            }

            prev_segment_time = segment_time;
        }

        ret = av_interleaved_write_frame(oc, &packet);
        if (ret < 0) {
            fprintf(stderr, "Warning: Could not write frame of stream\n");
        }
        else if (ret > 0) {
            fprintf(stderr, "End of stream requested\n");
            av_free_packet(&packet);
            break;
        }

        av_free_packet(&packet);
    } while (1);


    close_context(&oc, &video_st);

    return 0;
}